Skip to content

Commit b3036f5

Browse files
authored
Merge pull request #1203 from somtochiama/fix-helm-path
Preserve url encoded path in normalized helm repository URL
2 parents a302c71 + 64139e7 commit b3036f5

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

internal/helm/repository/utils.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,16 @@ func NormalizeURL(repositoryURL string) (string, error) {
4747

4848
if u.Scheme == helmreg.OCIScheme {
4949
u.Path = strings.TrimRight(u.Path, "/")
50+
// we perform the same operation on u.RawPath so that it will be a valid encoding
51+
// of u.Path. This allows u.EscapedPath() (which is used in computing u.String()) to return
52+
// the correct value when the path is url encoded.
53+
// ref: https://pkg.go.dev/net/url#URL.EscapedPath
54+
u.RawPath = strings.TrimRight(u.RawPath, "/")
5055
return u.String(), nil
5156
}
5257

5358
u.Path = strings.TrimRight(u.Path, "/") + "/"
59+
u.RawPath = strings.TrimRight(u.RawPath, "/") + "/"
5460
return u.String(), nil
5561
}
5662

internal/helm/repository/utils_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ func TestNormalizeURL(t *testing.T) {
6464
url: "http://example.com/?st=pr",
6565
want: "http://example.com/?st=pr",
6666
},
67+
{
68+
name: "url with encoded path",
69+
url: "http://example.com/next%2Fpath",
70+
want: "http://example.com/next%2Fpath/",
71+
},
72+
{
73+
name: "url with encoded path and slash",
74+
url: "http://example.com/next%2Fpath/",
75+
want: "http://example.com/next%2Fpath/",
76+
},
6777
{
6878
name: "empty url",
6979
url: "",

0 commit comments

Comments
 (0)