From 123f6a8cee92a692af12c77d82cd15cf3515e39b Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Mon, 25 May 2020 20:26:56 +0200 Subject: [PATCH] Fix memory reusage bug with auth Fixes #814 --- client_test.go | 2 +- uri.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client_test.go b/client_test.go index 5166afd..f5c9de9 100644 --- a/client_test.go +++ b/client_test.go @@ -112,7 +112,7 @@ func TestClientURLAuth(t *testing.T) { for up, expected := range cases { req := AcquireRequest() req.Header.SetMethod(MethodGet) - req.SetRequestURI("http://" + up + "example.com") + req.SetRequestURI("http://" + up + "example.com/foo/bar") if err := c.Do(req, nil); err != nil { t.Fatal(err) } diff --git a/uri.go b/uri.go index 9d64db8..a8b915a 100644 --- a/uri.go +++ b/uri.go @@ -284,11 +284,11 @@ func (u *URI) parse(host, uri []byte, isTLS bool) { host = host[n+1:] if n := bytes.Index(auth, strColon); n >= 0 { - u.username = auth[:n] - u.password = auth[n+1:] + u.username = append(u.username[:0], auth[:n]...) + u.password = append(u.password[:0], auth[n+1:]...) } else { - u.username = auth - u.password = auth[:0] // Make sure it's not nil + u.username = append(u.username[:0], auth...) + u.password = u.password[:0] } }