Fix helm repo index with encoded URLs

Signed-off-by: Mathieu Parent <math.parent@gmail.com>
pull/9825/head
Mathieu Parent 3 years ago committed by Mathieu Parent
parent e7bb860d9a
commit 50ce24ef56

@ -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