From 75b4afaa33a02ff01f041cf58a01535bca770cd6 Mon Sep 17 00:00:00 2001 From: Luke Hoban Date: Wed, 28 Nov 2018 11:15:49 -0800 Subject: [PATCH] Allow missing trailing '/' in --repo url (#4956) Apply the same procedure to allow missing trailing slash in repo base URLs used in `repo/chart` inputs to `--repo` inputs. Fixes #4954. Signed-off-by: Luke Hoban --- pkg/repo/chartrepo.go | 4 +++- pkg/repo/chartrepo_test.go | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/repo/chartrepo.go b/pkg/repo/chartrepo.go index cd9d6c547..c512c5b7e 100644 --- a/pkg/repo/chartrepo.go +++ b/pkg/repo/chartrepo.go @@ -270,10 +270,12 @@ func ResolveReferenceURL(baseURL, refURL string) (string, error) { return "", fmt.Errorf("failed to parse %s as URL: %v", refURL, err) } + // We need a trailing slash for ResolveReference to work, but make sure there isn't already one + parsedBaseURL.Path = strings.TrimSuffix(parsedBaseURL.Path, "/") + "/" + resolvedURL := parsedBaseURL.ResolveReference(parsedRefURL) // if the base URL contains query string parameters, // propagate them to the child URL but only if the // refURL is relative to baseURL - resolvedURL := parsedBaseURL.ResolveReference(parsedRefURL) if (resolvedURL.Hostname() == parsedBaseURL.Hostname()) && (resolvedURL.Port() == parsedBaseURL.Port()) { resolvedURL.RawQuery = parsedBaseURL.RawQuery } diff --git a/pkg/repo/chartrepo_test.go b/pkg/repo/chartrepo_test.go index 19071872d..a2f1daeb8 100644 --- a/pkg/repo/chartrepo_test.go +++ b/pkg/repo/chartrepo_test.go @@ -287,6 +287,14 @@ func TestResolveReferenceURL(t *testing.T) { t.Errorf("%s", chartURL) } + chartURL, err = ResolveReferenceURL("http://localhost:8123/charts", "nginx-0.2.0.tgz") + if err != nil { + t.Errorf("%s", err) + } + if chartURL != "http://localhost:8123/charts/nginx-0.2.0.tgz" { + t.Errorf("%s", chartURL) + } + chartURL, err = ResolveReferenceURL("http://localhost:8123/charts/?st=2018-08-06T22%3A59%3A04Z&se=2018-08-07T22%3A59%3A04Z&sp=rl&sv=2018-03-28&sr=c&sig=cyqM4%2F5G7HNk%2F3faaHSDMaWxFxefCglvZlYSnmQBwiY%3D", "nginx-0.2.0.tgz") if err != nil { t.Errorf("%s", err)