]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/xml: fix copy bug
authorRuss Cox <rsc@golang.org>
Tue, 22 Nov 2011 17:31:33 +0000 (12:31 -0500)
committerRuss Cox <rsc@golang.org>
Tue, 22 Nov 2011 17:31:33 +0000 (12:31 -0500)
Fixes #2484.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5417059

src/pkg/encoding/xml/xml.go
src/pkg/encoding/xml/xml_test.go

index 216d8889b239a92805eff6b7d7af0647b22d3b21..d67a299f5bb657e87c58b366efac3aef8d407e8c 100644 (file)
@@ -61,7 +61,7 @@ type StartElement struct {
 
 func (e StartElement) Copy() StartElement {
        attrs := make([]Attr, len(e.Attr))
-       copy(e.Attr, attrs)
+       copy(attrs, e.Attr)
        e.Attr = attrs
        return e
 }
index 828fac53ab334839767ebffdad8223dd16a89f68..25ffc917dcb135c3e8068405af0510d6a2530ee7 100644 (file)
@@ -486,10 +486,13 @@ func TestCopyTokenStartElement(t *testing.T) {
        elt := StartElement{Name{"", "hello"}, []Attr{{Name{"", "lang"}, "en"}}}
        var tok1 Token = elt
        tok2 := CopyToken(tok1)
+       if tok1.(StartElement).Attr[0].Value != "en" {
+               t.Error("CopyToken overwrote Attr[0]")
+       }
        if !reflect.DeepEqual(tok1, tok2) {
                t.Error("CopyToken(StartElement) != StartElement")
        }
-       elt.Attr[0] = Attr{Name{"", "lang"}, "de"}
+       tok1.(StartElement).Attr[0] = Attr{Name{"", "lang"}, "de"}
        if reflect.DeepEqual(tok1, tok2) {
                t.Error("CopyToken(CharData) uses same buffer.")
        }