Properly copy query arguments in URI.CopyTo

This commit is contained in:
Aliaksandr Valialkin
2016-02-19 20:17:37 +02:00
parent be49d3027a
commit 58e4dea85d
2 changed files with 16 additions and 1 deletions
+2 -1
View File
@@ -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.
+14
View File
@@ -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)
}