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 <luke@pulumi.com>
pull/4981/head
Luke Hoban 6 years ago committed by Matthew Fisher
parent 5584e5c5d8
commit 75b4afaa33

@ -270,10 +270,12 @@ func ResolveReferenceURL(baseURL, refURL string) (string, error) {
return "", fmt.Errorf("failed to parse %s as URL: %v", refURL, err) 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, // if the base URL contains query string parameters,
// propagate them to the child URL but only if the // propagate them to the child URL but only if the
// refURL is relative to baseURL // refURL is relative to baseURL
resolvedURL := parsedBaseURL.ResolveReference(parsedRefURL)
if (resolvedURL.Hostname() == parsedBaseURL.Hostname()) && (resolvedURL.Port() == parsedBaseURL.Port()) { if (resolvedURL.Hostname() == parsedBaseURL.Hostname()) && (resolvedURL.Port() == parsedBaseURL.Port()) {
resolvedURL.RawQuery = parsedBaseURL.RawQuery resolvedURL.RawQuery = parsedBaseURL.RawQuery
} }

@ -287,6 +287,14 @@ func TestResolveReferenceURL(t *testing.T) {
t.Errorf("%s", chartURL) 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") 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 { if err != nil {
t.Errorf("%s", err) t.Errorf("%s", err)

Loading…
Cancel
Save