File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed
Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 : "" ,
You can’t perform that action at this time.
0 commit comments