pull/9825/merge
Mathieu Parent 13 hours ago committed by GitHub
commit 78ae9cb0cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -33,10 +33,19 @@ func URLJoin(baseURL string, paths ...string) (string, error) {
if err != nil {
return "", err
}
if u.RawPath == "" {
u.RawPath = u.Path
}
// We want path instead of filepath because path always uses /.
all := []string{u.Path}
all := []string{u.RawPath}
all = append(all, paths...)
u.Path = path.Join(all...)
u.RawPath = path.Join(all...)
u.Path, err = url.PathUnescape(u.RawPath)
if err != nil {
return "", err
}
return u.String(), nil
}

@ -28,6 +28,9 @@ func TestURLJoin(t *testing.T) {
{name: "URL, two paths", url: "http://example.com", paths: []string{"hello", "world"}, expect: "http://example.com/hello/world"},
{name: "URL, no paths", url: "http://example.com", paths: []string{}, expect: "http://example.com"},
{name: "basepath, two paths", url: "../example.com", paths: []string{"hello", "world"}, expect: "../example.com/hello/world"},
{name: "encoded parts", url: "../example.com", paths: []string{"hello", "world"}, expect: "../example.com/hello/world"},
{name: "Long URL with encoded path, non-encoded paths", url: "http://example.com/but%2ffirst", paths: []string{"part-1", "part-2"}, expect: "http://example.com/but%2ffirst/part-1/part-2"},
{name: "Long URL with encoded path, encoded paths", url: "http://example.com/but%2ffirst", paths: []string{"part%25-1", "part%25-2"}, expect: "http://example.com/but%2ffirst/part%25-1/part%25-2"},
}
for _, tt := range tests {

Loading…
Cancel
Save