-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: Decoder does not reject xml-ProcInst preceeded by other data #65691
Comments
Note: this also happens with |
@rsc per owners |
Thanks for the report. Would you be willing to send a CL? |
Sure |
This doesn't just affect whitespace, but also other tokens, which is definitely not correct: https://go.dev/play/p/7cfsv_Ez5UX |
Change https://go.dev/cl/564035 mentions this issue: |
The fix for this issue depends on an implicit assumption that the input stream of a |
@nkitchen I'm not sure that's the only way in which the Long-term we probably want an |
Change https://go.dev/cl/570175 mentions this issue: |
See my comments on CL 570175. At the least this change requires a proposal and a GODEBUG for compatibility. |
This reverts commit 8a0fbd7. Reason for revert: Breaking real-world tests inside Google, which means it probably breaks real-world tests outside Google. One instance I have seen is a <!-- --> comment (often a copyright notice) before the procinst. Another test checks that a canonicalizer can handle a test input that simply has procinsts mid-XML. XML is full of contradictions, XML implementations more so. If we are going to start being picky, that probably needs to be controlled by a GODEBUG (and a proposal). For #65691 (will reopen manually). Change-Id: Ib52d0944b1478e71744a2a35b271fdf7e1c972ca Reviewed-on: https://go-review.googlesource.com/c/go/+/570175 Reviewed-by: Than McIntosh <thanm@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Russ Cox <rsc@golang.org>
I think that after this |
Go version
go version go1.22.0 linux/amd64
Output of
go env
in your module/workspace:What did you do?
Playground link:
What did you see happen?
What did you expect to see?
The specification tells us that a valid XML document must not have whitespace before the
<?xml …?>
instruction (if present):However, both the
Decoder
andUnmarshal
accept an input with leading whitespace.This tripped us up, because we use the
Decoder
to convert an XML document into a token stream, manipulate that and then use anEncoder.EncodeToken
to translate it back into XML. This broke when fed such an invalid input, because theEncoder
checks this invariant (it returns an error), but theDecoder
doesn't: https://go.dev/play/p/Gv89nolZNtMThe text was updated successfully, but these errors were encountered: