diff --git a/pkg/downloader/chart_downloader.go b/pkg/downloader/chart_downloader.go index 575c94151..dbee53712 100644 --- a/pkg/downloader/chart_downloader.go +++ b/pkg/downloader/chart_downloader.go @@ -268,6 +268,9 @@ func (c *ChartDownloader) ResolveChartVersion(ref, version string) (*url.URL, er q := repoURL.Query() // We need a trailing slash for ResolveReference to work, but make sure there isn't already one repoURL.Path = strings.TrimSuffix(repoURL.Path, "/") + "/" + // The URL class has problems with URL-escaped paths if we don't + // modify both paths. See https://github.com/helm/helm/issues/9977 + repoURL.RawPath = strings.TrimSuffix(repoURL.RawPath, "/") + "/" u = repoURL.ResolveReference(u) u.RawQuery = q.Encode() // TODO add user-agent diff --git a/pkg/downloader/chart_downloader_test.go b/pkg/downloader/chart_downloader_test.go index 38a06671c..8b9d110cd 100644 --- a/pkg/downloader/chart_downloader_test.go +++ b/pkg/downloader/chart_downloader_test.go @@ -49,6 +49,7 @@ func TestResolveChartRef(t *testing.T) { {name: "reference, testing-relative repo", ref: "testing-relative/bar", expect: "http://example.com/helm/bar-1.2.3.tgz"}, {name: "reference, testing-relative-trailing-slash repo", ref: "testing-relative-trailing-slash/foo", expect: "http://example.com/helm/charts/foo-1.2.3.tgz"}, {name: "reference, testing-relative-trailing-slash repo", ref: "testing-relative-trailing-slash/bar", expect: "http://example.com/helm/bar-1.2.3.tgz"}, + {name: "reference, testing-url-encoded-path repo", ref: "testing-url-encoded-path/foo", expect: "http://example.com/path%2fpath/charts/foo-1.2.3.tgz"}, {name: "full URL, HTTPS, irrelevant version", ref: "https://example.com/foo-1.2.3.tgz", version: "0.1.0", expect: "https://example.com/foo-1.2.3.tgz", fail: true}, {name: "full URL, file", ref: "file:///foo-1.2.3.tgz", fail: true}, {name: "invalid", ref: "invalid-1.2.3", fail: true}, diff --git a/pkg/downloader/testdata/repositories.yaml b/pkg/downloader/testdata/repositories.yaml index 32bc395a0..f174ce9f5 100644 --- a/pkg/downloader/testdata/repositories.yaml +++ b/pkg/downloader/testdata/repositories.yaml @@ -16,6 +16,8 @@ repositories: url: "http://example.com/helm" - name: testing-relative-trailing-slash url: "http://example.com/helm/" + - name: testing-url-encoded-path + url: "http://example.com/path%2fpath" - name: testing-ca-file url: "https://example.com" certFile: "cert" diff --git a/pkg/downloader/testdata/repository/testing-url-encoded-path-index.yaml b/pkg/downloader/testdata/repository/testing-url-encoded-path-index.yaml new file mode 100644 index 000000000..857248daa --- /dev/null +++ b/pkg/downloader/testdata/repository/testing-url-encoded-path-index.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +entries: + foo: + - name: foo + description: Foo Chart With URL-Encoded Path + home: https://helm.sh/helm + keywords: [] + maintainers: [] + sources: + - https://example.com/path%2fpath + urls: + - charts/foo-1.2.3.tgz + version: 1.2.3 + checksum: 0e6661f193211d7a5206918d42f5c2a9470b737d + apiVersion: v2