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

proposal: encoding/xml: Return a SyntaxError for unmatched start elements at EOF #11405

Closed
rsto opened this issue Jun 25, 2015 · 6 comments
Closed

Comments

@rsto
Copy link
Contributor

rsto commented Jun 25, 2015

I propose to make the xml.Decoder's Token routine fail with a syntax error, when the XML input contains unmatched start elements and the end of the stream.

Background

The xml.Decoder's Token routine returns successfully for input even if the XML content includes not properly closed start elements. For example, the following input

<root><bar></bar>

causes Token to return nil, io.EOF at the end of the stream, despite the unmatched "root" start element.

In my understanding Token should reject syntactically incorrect XML like this with an error.

This is also indicated by the following statement of the godoc of Token (emphasis mine)

Token guarantees that the StartElement and EndElement tokens it returns are properly 
nested and *matched*: if Token encounters an unexpected end element, it will return an 
error.

Proposal

I propose that a xml.Decoder's Token routine should return xml.SyntaxError for dangling start elements at the end of the stream. To do so, I have a CL ready for submission. Should this go through the proposed proposal process? Should this wait until Go 1.6?

Working example: http://play.golang.org/p/Fs6NPvDLu0
Verified on Go version: 1.4.2 and 1.5 development version (go version devel +751eef8).

[edited for clarity]
[edited to serve as a proposal for the proposal process]

@rsto
Copy link
Contributor Author

rsto commented Jun 29, 2015

@nigeltao Who could I ping for a comment? I can send a CL over for discussion but would prefer to first get feedback if this should even be fixed (and if so, what's the release target).

@nigeltao nigeltao self-assigned this Jun 30, 2015
@nigeltao
Copy link
Contributor

The Decoder.Token doc comment, which you linked to, does make your proposal sound reasonable. CC'ing @rsc.

As for the proposal process, TBH I'm as new to it as you are, but submitting a proposal seems fine.

In any case, this should wait until 1.6.

@rsto rsto changed the title encoding/xml: Token returns nil,io.EOF despite unmatched start elements proposal: encoding/xml: Token returns nil,io.EOF despite unmatched start elements Jul 3, 2015
@rsto rsto changed the title proposal: encoding/xml: Token returns nil,io.EOF despite unmatched start elements proposal: encoding/xml: Return a SyntaxError for unmatched start elements at EOF Jul 3, 2015
@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Jul 11, 2015
@rsc
Copy link
Contributor

rsc commented Sep 3, 2015

I think we should try this. However, it changes the behavior of existing programs, so we will need to call this out very explicitly in the release notes.

@rsto
Copy link
Contributor Author

rsto commented Sep 3, 2015

Great! I plan to send a CL over the weekend. Please let me know if you would like to see a design doc first.

@rsto
Copy link
Contributor Author

rsto commented Sep 5, 2015

The CL lives at https://go-review.googlesource.com/#/c/14315/

@gopherbot
Copy link

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

@golang golang locked and limited conversation to collaborators Sep 22, 2016
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

6 participants