encoding/xml: encoding a start token with a namespace set in Name and Attr results in invalid XML #42807
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
https://play.golang.org/p/ZK8yhFoVwW9
What did you expect to see?
One "xmlns" attribute.
What did you see instead?
Two "xmlns" attributes.
While the provided example is obviously very contrived this can happen in the real world (without a user doing something silly like manually adding a second xmlns attribute) in the situation where the user decodes some XML, makes modifications to the tokens, then encodes those tokens somewhere else (probably a fairly common use case). The decoder will add the "xmlns" attribute and fill out Name, then the encoder will duplicate it. The user would have to manually remove xmlns before encoding, or use
RawToken
(but this is not an option if the decoder is an arbitraryxml.TokenReader
so this isn't always possible). Skipping xmlns attributes on marshal ifstart.Name
is set is a simple patch that would fix this issue.The text was updated successfully, but these errors were encountered: