1
0
mirror of https://github.com/golang/go synced 2024-11-20 06:44:40 -07:00

encoding/xml: fix copy bug

Fixes #2484.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5417059
This commit is contained in:
Russ Cox 2011-11-22 12:31:33 -05:00
parent 6e3e380923
commit fe838c2ddb
2 changed files with 5 additions and 2 deletions

View 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
}

View 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.")
}