-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: Add (*Encoder).Close() to check for unclosed elements #53346
Comments
This proposal has been added to the active column of the proposals project |
Overall this seems simple and reasonable to me. |
Yes, that's definitely the intention. |
Based on the discussion above, this proposal seems like a likely accept. |
No change in consensus, so accepted. 🎉 |
@rsc I'll try to send a CL, unless you tell me not to. |
Change https://go.dev/cl/424777 mentions this issue: |
When using (*xml.Encoder).EncodeToken, the
Encoder
checks for mismatched elements. That is, it returns an error if e.g. a<a>
element is closed with a</b>
token or if there is an extra</c>
token after all elements have already been closed.However, if the user simply forgets to close all elements, the
Encoder
emits incorrect XML without reporting an error. See this code, for an example. So currently, the user must track the tokens they encode themselves, to make sure the emitted XML is valid.Flush
returns anerror
, but as it is possible to encode more tokens afterFlush
has been called, it can't complain about unclosed elements itself.I thus propose to add a new method to
Encoder
:Naming the method
Close
is an indication that it should be called and the returned error should be checked by the user.The text was updated successfully, but these errors were encountered: