parent
1177a19a5b
commit
561f459364
|
@ -129,8 +129,8 @@ func URLJoin(base string, elems ...string) string {
|
|||
return ""
|
||||
}
|
||||
joinedURL := baseURL.ResolveReference(argURL).String()
|
||||
if !baseURL.IsAbs() {
|
||||
return joinedURL[1:] // Removing leading '/'
|
||||
if !baseURL.IsAbs() && !strings.HasPrefix(base, "/") {
|
||||
return joinedURL[1:] // Removing leading '/' if needed
|
||||
}
|
||||
return joinedURL
|
||||
}
|
||||
|
|
|
@ -85,6 +85,12 @@ func TestURLJoin(t *testing.T) {
|
|||
"a/", "b/c/", "/../d/"),
|
||||
newTest("https://try.gitea.io/a/b/c#d",
|
||||
"https://try.gitea.io", "a/b", "c#d"),
|
||||
newTest("/a/b/d",
|
||||
"/a/", "b/c/", "/../d/"),
|
||||
newTest("/a/b/c",
|
||||
"/a", "b/c/"),
|
||||
newTest("/a/b/c#hash",
|
||||
"/a", "b/c#hash"),
|
||||
} {
|
||||
assert.Equal(t, test.Expected, URLJoin(test.Base, test.Elements...))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue