Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/xml: StartElement.Copy, swapped "copy" function call arguments #2484

Closed
nsf opened this issue Nov 19, 2011 · 2 comments
Closed

encoding/xml: StartElement.Copy, swapped "copy" function call arguments #2484

nsf opened this issue Nov 19, 2011 · 2 comments

Comments

@nsf
Copy link

nsf commented Nov 19, 2011

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)
@rsc
Copy link
Contributor

rsc commented Nov 21, 2011

Comment 1:

Thanks.  Fix out.

@rsc
Copy link
Contributor

rsc commented Nov 22, 2011

Comment 2:

This issue was closed by revision fe838c2.

Status changed to Fixed.

@nsf nsf added fixed labels Nov 22, 2011
@mikioh 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
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants