You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just take a look at it:
func (e StartElement) Copy() StartElement {
attrs := make([]Attr, len(e.Attr))
copy(e.Attr, attrs)
e.Attr = attrs
return e
}
"copy" function call arguments should be swapped. This method zeroes
"Attr" field during the copy process.
Code that illustrates the issue:
------------------------------
package main
import "encoding/xml"
import "bytes"
var test = `<x a="1" b="2" c="3"/>`
func main() {
b := bytes.NewBufferString(test)
parser := xml.NewParser(b)
t, _ := parser.Token()
se := t.(xml.StartElement)
println("before copy")
println(se.Name.Local)
for _, a := range se.Attr {
println(a.Name.Local)
}
se = se.Copy()
println("after copy")
println(se.Name.Local)
for _, a := range se.Attr {
println(a.Name.Local)
}
}
------------------------------
output:
==============================
before copy
x
a
b
c
after copy
x
==============================
Issue was spotted on the latest weekly (2011-11-18)
The text was updated successfully, but these errors were encountered:
mikioh
changed the title
Method xml.StartElement.Copy, swapped "copy" function call arguments
encoding/xml: StartElement.Copy, swapped "copy" function call arguments
Jan 9, 2015
The text was updated successfully, but these errors were encountered: