d8a994ef24", TestRepoURL)
- test(tmp, ""+TestOrgRepo+"@d8a994ef24", "https://localhost/forgejo/forgejo")
- test(
+ assert(tmp, "d8a994ef24", TestRepoURLWithoutSlash)
+ assert(tmp, ""+TestOrgRepo+"@d8a994ef24", "/forgejo/forgejo")
+ assert(
tmp+"#diff-2",
"d8a994ef24 (diff-2)",
TestRepoURL,
)
- test(
+ assert(
tmp+"#diff-953bb4f01b7c77fa18f0cd54211255051e647dbc",
"d8a994ef24 (diff-953bb4f01b)",
- TestRepoURL,
+ TestRepoURLWithoutSlash,
)
// render other commit URLs
tmp = "https://external-link.gitea.io/go-gitea/gitea/commit/d8a994ef243349f321568f9e36d5c3f444b99cae#diff-2"
- test(tmp, "d8a994ef24 (diff-2)", "https://external-link.gitea.io/go-gitea/gitea")
- test(tmp, "go-gitea/gitea@d8a994ef24 (diff-2)", TestRepoURL)
+ assert(tmp, "external-link.gitea.io/go-gitea/gitea@d8a994ef24 (diff-2)", TestOrgRepo)
+ defer test.MockVariableValue(&setting.AppURL, "https://external-link.gitea.io/")()
+ assert(tmp, "d8a994ef24 (diff-2)", "https://external-link.gitea.io/go-gitea/gitea")
- tmp = "http://localhost:3000/gogits/gogs/src/commit/190d9492934af498c3f669d6a2431dc5459e5b20"
- test(tmp, "190d949293", "http://localhost:3000/gogits/gogs")
- test(tmp, "gogits/gogs@190d949293", "https://external-link.gitea.io/go-gitea/gitea")
+ tmp = TestAppURL + "gogits/gogs/src/commit/190d9492934af498c3f669d6a2431dc5459e5b20"
+ assert(tmp, "localhost:3000/gogits/gogs@190d949293", "https://external-link.gitea.io/go-gitea/gitea")
+ defer test.MockVariableValue(&setting.AppURL, TestAppURL)()
+ assert(tmp, "190d949293", "http://localhost:3000/gogits/gogs")
tmp = "http://localhost:3000/sub/gogits/gogs/src/commit/190d9492934af498c3f669d6a2431dc5459e5b20"
- test(tmp, "190d949293", "http://localhost:3000/sub/gogits/gogs")
- test(tmp, "gogits/gogs@190d949293", "http://localhost:3000/gogits/gogs")
- test(tmp, "gogits/gogs@190d949293", "https://external-link.gitea.io/go-gitea/gitea")
+ assert(tmp, "localhost:3000/sub/gogits/gogs@190d949293", TestRepoURLWithoutSlash)
+ assert(tmp, "localhost:3000/sub/gogits/gogs@190d949293", "https://external-link.gitea.io/go-gitea/gitea")
+ defer test.MockVariableValue(&setting.AppURL, TestAppURL+"sub/")()
+ assert(tmp, "190d949293", "http://localhost:3000/sub/gogits/gogs")
tmp = "http://localhost:3000/sub1/sub2/sub3/gogits/gogs/src/commit/190d9492934af498c3f669d6a2431dc5459e5b20"
- test(tmp, "190d949293", "http://localhost:3000/sub1/sub2/sub3/gogits/gogs")
- test(tmp, "gogits/gogs@190d949293", "http://localhost:3000/sub1/gogits/gogs")
- test(tmp, "gogits/gogs@190d949293", "https://external-link.gitea.io/go-gitea/gitea")
+ defer test.MockVariableValue(&setting.AppURL, TestAppURL+"sub1/sub2/sub3/")()
+ assert(tmp, "190d949293", "http://localhost:3000/sub1/sub2/sub3/gogits/gogs")
+ defer test.MockVariableValue(&setting.AppURL, TestAppURL)()
+ assert(tmp, "localhost:3000/sub1/sub2/sub3/gogits/gogs@190d949293", "http://localhost:3000/sub1/gogits/gogs")
+ assert(tmp, "localhost:3000/sub1/sub2/sub3/gogits/gogs@190d949293", "https://external-link.gitea.io/go-gitea/gitea")
// if the repository happens to be named like one of the known app routes (e.g. `src`),
// we can parse the URL correctly, if there is no sub path
tmp = "http://localhost:3000/gogits/src/commit/190d9492934af498c3f669d6a2431dc5459e5b20"
- test(tmp, "gogits/src@190d949293", TestRepoURL)
+ assert(tmp, "gogits/src@190d949293", TestRepoURL)
tmp = "http://localhost:3000/gogits/src/src/commit/190d9492934af498c3f669d6a2431dc5459e5b20"
- test(tmp, "gogits/src@190d949293", TestRepoURL)
+ assert(tmp, "gogits/src@190d949293", TestRepoURL)
// but if there is a sub path, we cannot reliably distinguish the repo name from the app route
tmp = "http://localhost:3000/sub/gogits/src/commit/190d9492934af498c3f669d6a2431dc5459e5b20"
- test(tmp, "sub/gogits@190d949293", TestRepoURL)
+ assert(tmp, "sub/gogits@190d949293", TestRepoURL)
})
t.Run("Compare", func(t *testing.T) {
tmp := util.URLJoin(TestRepoURL, "compare", "d8a994ef243349f321568f9e36d5c3f444b99cae..190d9492934af498c3f669d6a2431dc5459e5b20")
- test(tmp, "d8a994ef24..190d949293", TestRepoURL)
- test(tmp, ""+TestOrgRepo+"@d8a994ef24..190d949293", "https://localhost/forgejo/forgejo")
+ assert(tmp, "d8a994ef24..190d949293", TestRepoURL)
+ assert(tmp, ""+TestOrgRepo+"@d8a994ef24..190d949293", "https://localhost/forgejo/forgejo")
+ defer test.MockVariableValue(&setting.AppURL, TestAppURL+"sub/")()
tmp = "http://localhost:3000/sub/gogits/gogs/compare/190d9492934af498c3f669d6a2431dc5459e5b20..d8a994ef243349f321568f9e36d5c3f444b99cae"
- test(tmp, "190d949293..d8a994ef24", "http://localhost:3000/sub/gogits/gogs")
- test(tmp, "gogits/gogs@190d949293..d8a994ef24", "http://localhost:3000/gogits/gogs")
- test(tmp, "gogits/gogs@190d949293..d8a994ef24", "https://external-link.gitea.io/go-gitea/gitea")
+ assert(tmp, "190d949293..d8a994ef24", "http://localhost:3000/sub/gogits/gogs")
+ assert(tmp, "gogits/gogs@190d949293..d8a994ef24", "http://localhost:3000/sub/gogits/gugs")
+ defer test.MockVariableValue(&setting.AppURL, "https://external-link.gitea.io/")()
+ assert(tmp, "localhost:3000/sub/gogits/gogs@190d949293..d8a994ef24", "https://external-link.gitea.io/go-gitea/gitea")
+ defer test.MockVariableValue(&setting.AppURL, TestAppURL+"sub1/sub2/sub3/")()
tmp = "http://localhost:3000/sub1/sub2/sub3/gogits/gogs/compare/190d9492934af498c3f669d6a2431dc5459e5b20..d8a994ef243349f321568f9e36d5c3f444b99cae"
- test(tmp, "190d949293..d8a994ef24", "http://localhost:3000/sub1/sub2/sub3/gogits/gogs")
- test(tmp, "gogits/gogs@190d949293..d8a994ef24", "http://localhost:3000/sub1/gogits/gogs")
- test(tmp, "gogits/gogs@190d949293..d8a994ef24", "https://external-link.gitea.io/go-gitea/gitea")
+ assert(tmp, "190d949293..d8a994ef24", "http://localhost:3000/sub1/sub2/sub3/gogits/gogs")
+ assert(tmp, "gogits/gogs@190d949293..d8a994ef24", "/gogits/gous")
+ assert(tmp, "gogits/gogs@190d949293..d8a994ef24", "https://external-link.gitea.io/go-gitea/gitea")
tmp = "https://codeberg.org/forgejo/forgejo/compare/8bbac4c679bea930c74849c355a60ed3c52f8eb5...e2278e5a38187a1dc84dc41d583ec8b44e7257c1?files=options/locale/locale_fi-FI.ini"
- test(tmp, "8bbac4c679...e2278e5a38 (options/locale/locale_fi-FI.ini)", "https://codeberg.org/forgejo/forgejo")
- test(tmp, "forgejo/forgejo@8bbac4c679...e2278e5a38 (options/locale/locale_fi-FI.ini)", TestRepoURL)
- test(tmp+".", "forgejo/forgejo@8bbac4c679...e2278e5a38 (options/locale/locale_fi-FI.ini).", TestRepoURL)
+ assert(tmp, "codeberg.org/forgejo/forgejo@8bbac4c679...e2278e5a38 (options/locale/locale_fi-FI.ini)", TestRepoURL)
+ assert(tmp+".", "codeberg.org/forgejo/forgejo@8bbac4c679...e2278e5a38 (options/locale/locale_fi-FI.ini).", TestRepoURL)
+ defer test.MockVariableValue(&setting.AppURL, "https://codeberg.org/")()
+ assert(tmp, "8bbac4c679...e2278e5a38 (options/locale/locale_fi-FI.ini)", "https://codeberg.org/forgejo/forgejo")
tmp = "https://codeberg.org/forgejo/forgejo/compare/8bbac4c679bea930c74849c355a60ed3c52f8eb5...e2278e5a38187a1dc84dc41d583ec8b44e7257c1?files=options/locale/locale_fi-FI.ini#L2"
- test(tmp, "8bbac4c679...e2278e5a38 (options/locale/locale_fi-FI.ini#L2)", "https://codeberg.org/forgejo/forgejo")
+ assert(tmp, "8bbac4c679...e2278e5a38 (options/locale/locale_fi-FI.ini#L2)", "https://codeberg.org/forgejo/forgejo")
})
t.Run("Invalid URLs", func(t *testing.T) {
tmp := "https://local host/gogits/src/commit/190d9492934af498c3f669d6a2431dc5459e5b20"
- test(tmp, "https://local host/gogits/src/commit/190d9492934af498c3f669d6a2431dc5459e5b20", TestRepoURL)
+ assert(tmp, "https://local host/gogits/src/commit/190d9492934af498c3f669d6a2431dc5459e5b20", TestRepoURL)
})
}
func TestRender_IssueIndexPatternRef(t *testing.T) {
- setting.AppURL = TestAppURL
+ defer test.MockVariableValue(&setting.AppURL, TestAppURL)()
test := func(input, expected string) {
var buf strings.Builder
@@ -428,7 +439,7 @@ func TestRender_IssueIndexPatternRef(t *testing.T) {
}
func TestRender_FullIssueURLs(t *testing.T) {
- setting.AppURL = TestAppURL
+ defer test.MockVariableValue(&setting.AppURL, TestAppURL)()
test := func(input, expected string) {
var result strings.Builder
diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go
index 6c6658748a..2ff829e627 100644
--- a/modules/markup/html_test.go
+++ b/modules/markup/html_test.go
@@ -41,7 +41,7 @@ func TestMain(m *testing.M) {
}
func TestRender_Commits(t *testing.T) {
- setting.AppURL = markup.TestAppURL
+ defer test.MockVariableValue(&setting.AppURL, markup.TestAppURL)()
test := func(input, expected string) {
buffer, err := markup.RenderString(&markup.RenderContext{
Ctx: git.DefaultContext,
@@ -98,10 +98,19 @@ func TestRender_Commits(t *testing.T) {
fileStrangeChars := util.URLJoin(repo, "src", "commit", "eeb243c3395e1921c5d90e73bd739827251fc99d", "path", "to", "file%20%23.txt")
test(fileStrangeChars, ``)
+
+ commitLink := util.URLJoin(repo, "src", "commit", "eeb243c3395e1921c5d90e73bd739827251fc99d")
+ test(commitLink, ``)
+
+ crossCommitLink := util.URLJoin(markup.TestAppURL, "forgejo/forgejo", "src", "commit", "eeb243c3395e1921c5d90e73bd739827251fc99d")
+ test(crossCommitLink, ``)
+
+ extCommitLink := util.URLJoin("https://codeberg.org/", markup.TestOrgRepo, "src", "commit", "eeb243c3395e1921c5d90e73bd739827251fc99d")
+ test(extCommitLink, `codeberg.org/`+markup.TestOrgRepo+`@eeb243c339
localhost:3000/sub1/sub2/gogits/gogs@!1 (commit `+sha[0:10]+`)
`+markup.TestOrgRepo+`@!1 (commit `+sha[0:10]+`)
localhost:3000/sub1/sub2/gogits/gogs@!1 (commit `+sha[0:10]+`)
forgejo/forgejo@!7979 (commit 4d968c08e0)
codeberg.org/forgejo/forgejo@!7979 (commit 4d968c08e0)
783b039...da951ce", res.String())
+ assert.Equal(t, "domain/org/repo@783b039...da951ce", res.String())
}
func TestRender_FilePreview(t *testing.T) {
@@ -744,7 +754,7 @@ func TestRender_FilePreview(t *testing.T) {
defer test.MockVariableValue(&setting.Langs, []string{"en-US"})()
translation.InitLocales(t.Context())
- setting.AppURL = markup.TestAppURL
+ defer test.MockVariableValue(&setting.AppURL, markup.TestAppURL)()
markup.Init(&markup.ProcessorHelper{
GetRepoFileBlob: func(ctx context.Context, ownerName, repoName, commitSha, filePath string, language *string) (*git.Blob, error) {
gitRepo, err := git.OpenRepository(git.DefaultContext, "./tests/repo/repo1_filepreview")
@@ -884,7 +894,7 @@ func TestRender_FilePreview(t *testing.T) {
testRender(
urlWithSub,
- `gogits/gogs@190d949293/path/to/file.go (L2-L3)
localhost:3000/sub/gogits/gogs@190d949293/path/to/file.go (L2-L3)
first without sub 190d949293/path/to/file.go (L2-L3) second
first without sub localhost:3000/gogits/gogs@190d949293/path/to/file.go (L2-L3) second