Commit fe838c2d authored by Russ Cox's avatar Russ Cox

encoding/xml: fix copy bug

Fixes #2484.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5417059
parent 6e3e3809
...@@ -61,7 +61,7 @@ type StartElement struct { ...@@ -61,7 +61,7 @@ type StartElement struct {
func (e StartElement) Copy() StartElement { func (e StartElement) Copy() StartElement {
attrs := make([]Attr, len(e.Attr)) attrs := make([]Attr, len(e.Attr))
copy(e.Attr, attrs) copy(attrs, e.Attr)
e.Attr = attrs e.Attr = attrs
return e return e
} }
......
...@@ -486,10 +486,13 @@ func TestCopyTokenStartElement(t *testing.T) { ...@@ -486,10 +486,13 @@ func TestCopyTokenStartElement(t *testing.T) {
elt := StartElement{Name{"", "hello"}, []Attr{{Name{"", "lang"}, "en"}}} elt := StartElement{Name{"", "hello"}, []Attr{{Name{"", "lang"}, "en"}}}
var tok1 Token = elt var tok1 Token = elt
tok2 := CopyToken(tok1) tok2 := CopyToken(tok1)
if tok1.(StartElement).Attr[0].Value != "en" {
t.Error("CopyToken overwrote Attr[0]")
}
if !reflect.DeepEqual(tok1, tok2) { if !reflect.DeepEqual(tok1, tok2) {
t.Error("CopyToken(StartElement) != StartElement") 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) { if reflect.DeepEqual(tok1, tok2) {
t.Error("CopyToken(CharData) uses same buffer.") t.Error("CopyToken(CharData) uses same buffer.")
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment