From 0e9993253004665fe34bd6e794f763894927e0b4 Mon Sep 17 00:00:00 2001
From: silverwind
After this change, only links to the current instance, as identified by
`setting.AppURL` are turned into hash links:
There is still one notable [difference with
GitHub](https://github.com/silverwind/symlink-test/issues/20#issuecomment-3687535938)
where the second link should render like `user/repo@
d8a994ef24 (diff-2)")
+ test(tmp, ""+tmp+"")
}
func TestRender_FullIssueURLs(t *testing.T) {
diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go
index 76013ccd13d..5f873d29852 100644
--- a/modules/markup/html_test.go
+++ b/modules/markup/html_test.go
@@ -71,6 +71,7 @@ func TestRender_Commits(t *testing.T) {
}
func TestRender_CrossReferences(t *testing.T) {
+ defer testModule.MockVariableValue(&setting.AppURL, markup.TestAppURL)()
defer testModule.MockVariableValue(&markup.RenderBehaviorForTesting.DisableAdditionalAttributes, true)()
test := func(input, expected string) {
rctx := markup.NewTestRenderContext(markup.TestAppURL, localMetas).WithRelativePath("a.md")
@@ -98,17 +99,17 @@ func TestRender_CrossReferences(t *testing.T) {
util.URLJoin(markup.TestAppURL, "gogitea", "some-repo-name", "issues", "12345"),
``)
- inputURL := "https://host/a/b/commit/0123456789012345678901234567890123456789/foo.txt?a=b#L2-L3"
+ inputURL := setting.AppURL + "a/b/commit/0123456789012345678901234567890123456789/foo.txt?a=b#L2-L3"
test(
inputURL,
``)
- inputURL = "https://example.com/repo/owner/archive/0123456789012345678901234567890123456789.tar.gz"
+ inputURL = setting.AppURL + "repo/owner/archive/0123456789012345678901234567890123456789.tar.gz"
test(
inputURL,
``)
- inputURL = "https://example.com/owner/repo/commit/0123456789012345678901234567890123456789.patch?key=val"
+ inputURL = setting.AppURL + "owner/repo/commit/0123456789012345678901234567890123456789.patch?key=val"
test(
inputURL,
``)
@@ -575,13 +576,15 @@ func TestFuzz(t *testing.T) {
}
func TestIssue18471(t *testing.T) {
- data := `http://domain/org/repo/compare/783b039...da951ce`
+ defer testModule.MockVariableValue(&setting.AppURL, markup.TestAppURL)()
+
+ data := markup.TestAppURL + `org/repo/compare/783b039...da951ce`
var res strings.Builder
err := markup.PostProcessDefault(markup.NewTestRenderContext(localMetas), strings.NewReader(data), &res)
assert.NoError(t, err)
- assert.Equal(t, `783b039...da951ce`, res.String())
+ assert.Equal(t, `783b039...da951ce`, res.String())
}
func TestIsFullURL(t *testing.T) {
diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go
index 47b293e1e9b..8d6b3b3c80e 100644
--- a/modules/markup/markdown/markdown_test.go
+++ b/modules/markup/markdown/markdown_test.go
@@ -483,6 +483,9 @@ foo: bar
}
func TestRenderLinks(t *testing.T) {
+ defer test.MockVariableValue(&setting.AppURL, AppURL)()
+ defer test.MockVariableValue(&markup.RenderBehaviorForTesting.DisableAdditionalAttributes, true)()
+
input := ` space @mention-user${SPACE}${SPACE}
/just/a/path.bin
https://example.com/file.bin
@@ -520,9 +523,9 @@ mail@domain.com
-88fc37a3c0...12fc37a3c0 (hash)
+https://example.com/user/repo/compare/88fc37a3c0a4dda553bdcfc80c178a58247f42fb...12fc37a3c0a4dda553bdcfc80c178a58247f42fb#hash
com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb...12fc37a3c0a4dda553bdcfc80c178a58247f42fb pare
-88fc37a3c0
+https://example.com/user/repo/commit/88fc37a3c0a4dda553bdcfc80c178a58247f42fb
com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit
👍
mail@domain.com
@@ -530,10 +533,21 @@ com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit
#123
space