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: Unmarshal does not properly handle NCName in XML namespaces #9775

Open
fantasist opened this issue Feb 5, 2015 · 7 comments
Open
Labels
early-in-cycle A change that should be done early in the 3 month dev cycle. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@fantasist
Copy link

Example:
type A struct {
XMLName xml.Name xml:"a:B"
}
Struct A is marshaled to "<a:B></a:B>", as expected.
However if we run
a := A{}
xml.Unmarshal([]byte("<a:B></a:B>"), &a)

It results in an error saying "unexpected error: expected element type <a:B> but have "

@c4milo
Copy link
Member

c4milo commented Feb 5, 2015

This issue seems to be a duplicate of #6800

@mikioh mikioh changed the title xml.Unmarshal() does not properly handle namespace in XMLName field xml: Unmarshal does not properly handle namespace in XMLName field Feb 5, 2015
@mikioh
Copy link
Contributor

mikioh commented Feb 5, 2015

Dup of #6800.

@mikioh mikioh closed this as completed Feb 5, 2015
@mikioh mikioh changed the title xml: Unmarshal does not properly handle namespace in XMLName field encoding/xml: Unmarshal does not properly handle namespace in XMLName field Feb 5, 2015
@mikioh mikioh reopened this Mar 19, 2015
@mikioh mikioh changed the title encoding/xml: Unmarshal does not properly handle namespace in XMLName field encoding/xml: Unmarshal does not properly handle NCName in XML namespaces Mar 19, 2015
@rsc rsc added this to the Go1.5Maybe milestone Apr 10, 2015
@rsc rsc modified the milestones: Go1.5, Go1.5Maybe, Go1.6 Jul 20, 2015
@rsc
Copy link
Contributor

rsc commented Jul 23, 2015

See #11841.

@gopherbot
Copy link

CL https://golang.org/cl/12570 mentions this issue.

rsc added a commit that referenced this issue Jul 27, 2015
There is clearly work to do here with respect to xml name spaces,
but I don't believe the changes in this cycle are clearly correct.
The changes in this cycle have visible impact on the generated xml,
possibly breaking existing programs, and yet it's not clear that they
are the end of the story: there is still significant confusion about how
name spaces work or should work (see #9519, #9775, #8167, #7113).

I would like to wait to make breaking changes until we completely
understand what the behavior should be and can evaluate the benefit
of those breaking changes. My main concern here is that we will break
programs in Go 1.5 for the sake of name space adjustments and then
while trying to fix those other bugs we'll break programs in Go 1.6 too.
Let's wait until we know all the changes we want to make before we
decide whether or how to break existing programs.

This CL reverts:

5ae822b encoding/xml: minor changes
bb7e665 encoding/xml: fix xmlns= behavior
9f9d66d encoding/xml: fix default namespace of tags
b69ea01 encoding/xml: fix namespaces in a>b tags
3be158d encoding/xml: encoding name spaces correctly

and adjusts tests from

a9dddb5 encoding/xml: add more EncodeToken tests.

to expect Go 1.4 behavior.

I have confirmed that the name space parts of the test suite
as of this CL passes against the Go 1.4 encoding/xml package,
indicating that this CL successfully restores the Go 1.4 behavior.

(Other tests do not, but that's because there were some real
bug fixes in this cycle that are being kept. Specifically, the
tests that don't pass in Go 1.4 are TestMarshal's NestedAndComment
case, TestEncodeToken's encoding of newlines, and
TestSimpleUseOfEncodeToken returning an error for invalid
token types.)

I also checked that the Go 1.4 tests pass when run against
this copy of the sources.

Fixes #11841.

Change-Id: I97de06761038b40388ef6e3a55547ff43edee7cb
Reviewed-on: https://go-review.googlesource.com/12570
Reviewed-by: Nigel Tao <nigeltao@golang.org>
@rsc
Copy link
Contributor

rsc commented Nov 25, 2015

Blocked on #13400.

@rsc rsc modified the milestones: Go1.7, Go1.6 Nov 25, 2015
@rsc rsc modified the milestones: Go1.8, Go1.7 May 18, 2016
@quentinmit quentinmit added NeedsFix The path to resolution is known, but the work has not been done. Blocked labels Oct 10, 2016
@rsc rsc modified the milestones: Go1.9Early, Go1.8 Oct 26, 2016
@bradfitz bradfitz modified the milestones: Go1.9Early, Go1.10Early May 3, 2017
@bradfitz bradfitz removed this from the Go1.9Early milestone May 3, 2017
@bradfitz bradfitz added early-in-cycle A change that should be done early in the 3 month dev cycle. and removed early-in-cycle A change that should be done early in the 3 month dev cycle. labels Jun 14, 2017
@bradfitz bradfitz modified the milestones: Go1.10Early, Go1.10 Jun 14, 2017
@rsc rsc modified the milestones: Go1.10, Go1.11 Nov 22, 2017
@iwdgo
Copy link
Contributor

iwdgo commented Apr 17, 2018

The provided example is invalid XML as the prefix a for element <a:B> is not bound. The prefix needs a declaration like xmlns:a="...". The reported error : expected element type <a:B> but have <B> points to the correct element.

@Demitroi
Copy link

Demitroi commented Apr 21, 2020

@fantasist

Here's an unmarshal wrapper that allows namespace prefix

https://play.golang.org/p/zLixkblqVOB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
early-in-cycle A change that should be done early in the 3 month dev cycle. NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

10 participants