Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve url encoded path in normalized helm repository URL #1203

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions internal/helm/repository/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,16 @@ func NormalizeURL(repositoryURL string) (string, error) {

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

u.Path = strings.TrimRight(u.Path, "/") + "/"
u.RawPath = strings.TrimRight(u.RawPath, "/") + "/"
return u.String(), nil
}

Expand Down
10 changes: 10 additions & 0 deletions internal/helm/repository/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ func TestNormalizeURL(t *testing.T) {
url: "http://example.com/?st=pr",
want: "http://example.com/?st=pr",
},
{
name: "url with encoded path",
url: "http://example.com/next%2Fpath",
want: "http://example.com/next%2Fpath/",
},
{
name: "url with encoded path and slash",
url: "http://example.com/next%2Fpath/",
want: "http://example.com/next%2Fpath/",
},
{
name: "empty url",
url: "",
Expand Down