From 58e4dea85db1b01e95b02e105b2a0e953c52694a Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 19 Feb 2016 20:17:37 +0200 Subject: [PATCH] Properly copy query arguments in URI.CopyTo --- uri.go | 3 ++- uri_test.go | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/uri.go b/uri.go index 49b30a9..a0e2744 100644 --- a/uri.go +++ b/uri.go @@ -62,7 +62,8 @@ func (u *URI) CopyTo(dst *URI) { dst.hash = append(dst.hash[:0], u.hash...) dst.host = append(dst.host[:0], u.host...) - dst.parsedQueryArgs = false + u.queryArgs.CopyTo(&dst.queryArgs) + dst.parsedQueryArgs = u.parsedQueryArgs // fullURI and requestURI shouldn't be copied, since they are created // from scratch on each FullURI() and RequestURI() call. diff --git a/uri_test.go b/uri_test.go index 5d489f5..3e519dc 100644 --- a/uri_test.go +++ b/uri_test.go @@ -7,6 +7,20 @@ import ( "time" ) +func TestURICopyToQueryArgs(t *testing.T) { + var u URI + a := u.QueryArgs() + a.Set("foo", "bar") + + var u1 URI + u.CopyTo(&u1) + a1 := u1.QueryArgs() + + if string(a1.Peek("foo")) != "bar" { + t.Fatalf("unexpected query args value %q. Expecting %q", a1.Peek("foo"), "bar") + } +} + func TestURIAcquireReleaseSequential(t *testing.T) { testURIAcquireRelease(t) }