From 3e41eefd1252012cb869d93e1f27b75b2876fe9b Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 20 Jan 2020 13:40:26 +0100 Subject: [PATCH] internal: properly encode path in Client.NewRequest --- internal/client.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/internal/client.go b/internal/client.go index a526364..7c42e41 100644 --- a/internal/client.go +++ b/internal/client.go @@ -75,11 +75,17 @@ func (c *Client) SetBasicAuth(username, password string) { } func (c *Client) NewRequest(method string, href string, body io.Reader) (*http.Request, error) { + hrefURL, err := url.Parse(href) + if err != nil { + return nil, fmt.Errorf("failed to parse request href %q: %v", href, err) + } + u := url.URL{ - Scheme: c.endpoint.Scheme, - User: c.endpoint.User, - Host: c.endpoint.Host, - Path: path.Join(c.endpoint.Path, href), + Scheme: c.endpoint.Scheme, + User: c.endpoint.User, + Host: c.endpoint.Host, + Path: path.Join(c.endpoint.Path, hrefURL.Path), + RawQuery: hrefURL.RawQuery, } return http.NewRequest(method, u.String(), body) }