diff --git a/cmd/helm/downloader/manager.go b/cmd/helm/downloader/manager.go index 82ab83ad5..723c283d3 100644 --- a/cmd/helm/downloader/manager.go +++ b/cmd/helm/downloader/manager.go @@ -278,6 +278,8 @@ func (m *Manager) parallelRepoUpdate(repos []*repo.Entry) { func urlsAreEqual(a, b string) bool { au, err := url.Parse(a) if err != nil { + a = filepath.Clean(a) + b = filepath.Clean(b) // If urls are paths, return true only if they are an exact match return a == b } @@ -285,6 +287,13 @@ func urlsAreEqual(a, b string) bool { if err != nil { return false } + + for _, u := range []*url.URL{au, bu} { + if u.Path == "" { + u.Path = "/" + } + u.Path = filepath.Clean(u.Path) + } return au.String() == bu.String() } diff --git a/cmd/helm/downloader/manager_test.go b/cmd/helm/downloader/manager_test.go index f21eef44b..d465dd286 100644 --- a/cmd/helm/downloader/manager_test.go +++ b/cmd/helm/downloader/manager_test.go @@ -84,3 +84,27 @@ func TestFindChartURL(t *testing.T) { } } + +func TestUrlsAreEqual(t *testing.T) { + for _, tt := range []struct { + a, b string + match bool + }{ + {"http://example.com", "http://example.com", true}, + {"http://example.com", "http://another.example.com", false}, + {"https://example.com", "https://example.com", true}, + {"http://example.com/", "http://example.com", true}, + {"https://example.com", "http://example.com", false}, + {"http://example.com/foo", "http://example.com/foo/", true}, + {"http://example.com/foo//", "http://example.com/foo/", true}, + {"http://example.com/./foo/", "http://example.com/foo/", true}, + {"http://example.com/bar/../foo/", "http://example.com/foo/", true}, + {"/foo", "/foo", true}, + {"/foo", "/foo/", true}, + {"/foo/.", "/foo/", true}, + } { + if tt.match != urlsAreEqual(tt.a, tt.b) { + t.Errorf("Expected %q==%q to be %t", tt.a, tt.b, tt.match) + } + } +}