From f697373abda5a44d86a07ac2e651dcd9ccd5e944 Mon Sep 17 00:00:00 2001 From: Rodrigo Chiossi Date: Tue, 18 Sep 2018 16:42:26 +0000 Subject: [PATCH] builder: Fix URL build for base URL with subpath When building the upstream URL, if the b.UpstreamURL was set do a url with a subpath included, the subpath was being discarded by URL.ResolveReference(). In order to preserve the subpath in the base, the provided subpath must be manually added to the base URL object. Signed-off-by: Rodrigo Chiossi --- builder/builder.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/builder/builder.go b/builder/builder.go index ad4a23e..89f1847 100644 --- a/builder/builder.go +++ b/builder/builder.go @@ -27,6 +27,7 @@ import ( "net/url" "os" "os/exec" + "path" "path/filepath" "runtime" "sort" @@ -171,17 +172,16 @@ func (b *Builder) getLatestUpstreamVersion() (string, error) { // buildUpstreamURL builds the full upstream URL based on a b.UpstreamURL and a // supplied subpath func (b *Builder) buildUpstreamURL(subpath string) (string, error) { - // Build the URL - end, err := url.Parse(subpath) - if err != nil { - return "", err - } base, err := url.Parse(b.UpstreamURL) if err != nil { return "", err } - return base.ResolveReference(end).String(), nil + for _, token := range strings.Split(subpath, "/") { + base.Path = path.Join(base.Path, token) + } + + return base.String(), nil } // DownloadFileFromUpstreamAsString will download a file from the Upstream URL