Remove util.URLJoin and replace all callers with direct path concatenation (#36867)
`util.URLJoin` was deprecated with unclear semantics (path normalization via `url.Parse`/`ResolveReference` that surprised callers). This removes it entirely and replaces all usages with straightforward `"/"` string concatenation. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: wxiaoguang <2114189+wxiaoguang@users.noreply.github.com>
This commit is contained in:
@@ -23,12 +23,12 @@ const (
|
||||
|
||||
// externalIssueLink an HTML link to an alphanumeric-style issue
|
||||
func externalIssueLink(baseURL, class, name string) string {
|
||||
return link(util.URLJoin(baseURL, name), class, name)
|
||||
return link(strings.TrimSuffix(baseURL, "/")+"/"+name, class, name)
|
||||
}
|
||||
|
||||
// numericLink an HTML to a numeric-style issue
|
||||
func numericIssueLink(baseURL, class string, index int, marker string) string {
|
||||
return link(util.URLJoin(baseURL, strconv.Itoa(index)), class, fmt.Sprintf("%s%d", marker, index))
|
||||
return link(strings.TrimSuffix(baseURL, "/")+"/"+strconv.Itoa(index), class, fmt.Sprintf("%s%d", marker, index))
|
||||
}
|
||||
|
||||
// link an HTML link
|
||||
@@ -116,7 +116,7 @@ func TestRender_IssueIndexPattern2(t *testing.T) {
|
||||
|
||||
links := make([]any, len(indices))
|
||||
for i, index := range indices {
|
||||
links[i] = numericIssueLink(util.URLJoin("/test-owner/test-repo", path), "ref-issue", index, marker)
|
||||
links[i] = numericIssueLink("/test-owner/test-repo/"+path, "ref-issue", index, marker)
|
||||
}
|
||||
expectedNil := fmt.Sprintf(expectedFmt, links...)
|
||||
testRenderIssueIndexPattern(t, s, expectedNil, NewTestRenderContext(TestAppURL, localMetas))
|
||||
@@ -210,7 +210,7 @@ func TestRender_IssueIndexPattern5(t *testing.T) {
|
||||
metas["regexp"] = pattern
|
||||
links := make([]any, len(ids))
|
||||
for i, id := range ids {
|
||||
links[i] = link(util.URLJoin("https://someurl.com/someUser/someRepo/", id), "ref-issue ref-external-issue", names[i])
|
||||
links[i] = link("https://someurl.com/someUser/someRepo/"+id, "ref-issue ref-external-issue", names[i])
|
||||
}
|
||||
|
||||
expected := fmt.Sprintf(expectedFmt, links...)
|
||||
@@ -288,11 +288,11 @@ func TestRender_AutoLink(t *testing.T) {
|
||||
}
|
||||
|
||||
// render valid issue URLs
|
||||
test(util.URLJoin(TestRepoURL, "issues", "3333"),
|
||||
numericIssueLink(util.URLJoin(TestRepoURL, "issues"), "ref-issue", 3333, "#"))
|
||||
test(TestRepoURL+"issues/3333",
|
||||
numericIssueLink(TestRepoURL+"issues", "ref-issue", 3333, "#"))
|
||||
|
||||
// render valid commit URLs
|
||||
tmp := util.URLJoin(TestRepoURL, "commit", "d8a994ef243349f321568f9e36d5c3f444b99cae")
|
||||
tmp := TestRepoURL + "commit/d8a994ef243349f321568f9e36d5c3f444b99cae"
|
||||
test(tmp, "<a href=\""+tmp+"\" class=\"commit\"><code>d8a994ef24</code></a>")
|
||||
tmp += "#diff-2"
|
||||
test(tmp, "<a href=\""+tmp+"\" class=\"commit\"><code>d8a994ef24 (diff-2)</code></a>")
|
||||
|
||||
@@ -34,15 +34,15 @@ func TestRender_Commits(t *testing.T) {
|
||||
|
||||
sha := "65f1bf27bc3bf70f64657658635e66094edbcb4d"
|
||||
repo := markup.TestAppURL + testRepoOwnerName + "/" + testRepoName + "/"
|
||||
commit := util.URLJoin(repo, "commit", sha)
|
||||
commit := repo + "commit/" + sha
|
||||
commitPath := "/user13/repo11/commit/" + sha
|
||||
tree := util.URLJoin(repo, "tree", sha, "src")
|
||||
tree := repo + "tree/" + sha + "/src"
|
||||
|
||||
file := util.URLJoin(repo, "commit", sha, "example.txt")
|
||||
file := repo + "commit/" + sha + "/example.txt"
|
||||
fileWithExtra := file + ":"
|
||||
fileWithHash := file + "#L2"
|
||||
fileWithHasExtra := file + "#L2:"
|
||||
commitCompare := util.URLJoin(repo, "compare", sha+"..."+sha)
|
||||
commitCompare := repo + "compare/" + sha + "..." + sha
|
||||
commitCompareWithHash := commitCompare + "#L2"
|
||||
|
||||
test(sha, `<p><a href="`+commitPath+`" rel="nofollow"><code>65f1bf27bc</code></a></p>`)
|
||||
@@ -90,14 +90,14 @@ func TestRender_CrossReferences(t *testing.T) {
|
||||
"/home/gitea/go-gitea/gitea#12345",
|
||||
`<p>/home/gitea/go-gitea/gitea#12345</p>`)
|
||||
test(
|
||||
util.URLJoin(markup.TestAppURL, "gogitea", "gitea", "issues", "12345"),
|
||||
`<p><a href="`+util.URLJoin(markup.TestAppURL, "gogitea", "gitea", "issues", "12345")+`" class="ref-issue" rel="nofollow">gogitea/gitea#12345</a></p>`)
|
||||
markup.TestAppURL+"gogitea/gitea/issues/12345",
|
||||
`<p><a href="`+markup.TestAppURL+`gogitea/gitea/issues/12345" class="ref-issue" rel="nofollow">gogitea/gitea#12345</a></p>`)
|
||||
test(
|
||||
util.URLJoin(markup.TestAppURL, "go-gitea", "gitea", "issues", "12345"),
|
||||
`<p><a href="`+util.URLJoin(markup.TestAppURL, "go-gitea", "gitea", "issues", "12345")+`" class="ref-issue" rel="nofollow">go-gitea/gitea#12345</a></p>`)
|
||||
markup.TestAppURL+"go-gitea/gitea/issues/12345",
|
||||
`<p><a href="`+markup.TestAppURL+`go-gitea/gitea/issues/12345" class="ref-issue" rel="nofollow">go-gitea/gitea#12345</a></p>`)
|
||||
test(
|
||||
util.URLJoin(markup.TestAppURL, "gogitea", "some-repo-name", "issues", "12345"),
|
||||
`<p><a href="`+util.URLJoin(markup.TestAppURL, "gogitea", "some-repo-name", "issues", "12345")+`" class="ref-issue" rel="nofollow">gogitea/some-repo-name#12345</a></p>`)
|
||||
markup.TestAppURL+"gogitea/some-repo-name/issues/12345",
|
||||
`<p><a href="`+markup.TestAppURL+`gogitea/some-repo-name/issues/12345" class="ref-issue" rel="nofollow">gogitea/some-repo-name#12345</a></p>`)
|
||||
|
||||
inputURL := setting.AppURL + "a/b/commit/0123456789012345678901234567890123456789/foo.txt?a=b#L2-L3"
|
||||
test(
|
||||
@@ -375,7 +375,7 @@ func TestRender_emoji(t *testing.T) {
|
||||
|
||||
func TestRender_ShortLinks(t *testing.T) {
|
||||
setting.AppURL = markup.TestAppURL
|
||||
tree := util.URLJoin(markup.TestRepoURL, "src", "master")
|
||||
tree := markup.TestRepoURL + "src/master"
|
||||
|
||||
test := func(input, expected string) {
|
||||
buffer, err := markdown.RenderString(markup.NewTestRenderContext(tree), input)
|
||||
@@ -383,15 +383,15 @@ func TestRender_ShortLinks(t *testing.T) {
|
||||
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(buffer)))
|
||||
}
|
||||
|
||||
url := util.URLJoin(tree, "Link")
|
||||
otherURL := util.URLJoin(tree, "Other-Link")
|
||||
encodedURL := util.URLJoin(tree, "Link%3F")
|
||||
imgurl := util.URLJoin(tree, "Link.jpg")
|
||||
otherImgurl := util.URLJoin(tree, "Link+Other.jpg")
|
||||
encodedImgurl := util.URLJoin(tree, "Link+%23.jpg")
|
||||
notencodedImgurl := util.URLJoin(tree, "some", "path", "Link%20#.jpg")
|
||||
renderableFileURL := util.URLJoin(tree, "markdown_file.md")
|
||||
unrenderableFileURL := util.URLJoin(tree, "file.zip")
|
||||
url := tree + "/Link"
|
||||
otherURL := tree + "/Other-Link"
|
||||
encodedURL := tree + "/Link%3F"
|
||||
imgurl := tree + "/Link.jpg"
|
||||
otherImgurl := tree + "/Link+Other.jpg"
|
||||
encodedImgurl := tree + "/Link+%23.jpg"
|
||||
notencodedImgurl := tree + "/some/path/Link%20#.jpg"
|
||||
renderableFileURL := tree + "/markdown_file.md"
|
||||
unrenderableFileURL := tree + "/file.zip"
|
||||
favicon := "http://google.com/favicon.ico"
|
||||
|
||||
test(
|
||||
|
||||
Reference in New Issue
Block a user