From 50ce24ef56a5907e06810107586959ad164a1143 Mon Sep 17 00:00:00 2001 From: Mathieu Parent Date: Thu, 17 Jun 2021 16:21:43 +0200 Subject: [PATCH] Fix helm repo index with encoded URLs Signed-off-by: Mathieu Parent --- internal/urlutil/urlutil.go | 13 +++++++++++-- internal/urlutil/urlutil_test.go | 3 +++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/urlutil/urlutil.go b/internal/urlutil/urlutil.go index a8cf7398c..57359c631 100644 --- a/internal/urlutil/urlutil.go +++ b/internal/urlutil/urlutil.go @@ -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 } diff --git a/internal/urlutil/urlutil_test.go b/internal/urlutil/urlutil_test.go index 82acc40fe..c3608fd6f 100644 --- a/internal/urlutil/urlutil_test.go +++ b/internal/urlutil/urlutil_test.go @@ -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 {