go/src/encoding
Axel Wagner 8a0fbd75a5 encoding/xml: reject XML declaration after start of document
The XML specification requires an XML declaration, if present, to only
appear at the very beginning of the document, not even preceded by
whitespace. The parser currently accepts it at any part of the input.

Rejecting whitespace at the beginning of the file might break too many
users. This change instead only rejects an XML declaration preceded by
a non-whitespace token *and* allows the Encoder to emit whitespace
before an XML declaration. This means that a token stream produced by
the Decoder can be passed to the Encoder without error, while we still
don't emit clearly invalid XML.

This might break programs depending on Decoder allowing arbitrary XML
before the XML declaration.

Fixes #65691.

Change-Id: Ib1d4b3116aee63f40fd377f90595780b4befd1ee
Reviewed-on: https://go-review.googlesource.com/c/go/+/564035
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-02-22 22:50:20 +00:00
..
ascii85 encoding: modernize Go documentation 2023-09-08 19:04:28 +00:00
asn1 encoding: modernize Go documentation 2023-09-08 19:04:28 +00:00
base32 encoding: modernize Go documentation 2023-09-08 19:04:28 +00:00
base64 encoding: modernize Go documentation 2023-09-08 19:04:28 +00:00
binary encoding: modernize Go documentation 2023-09-08 19:04:28 +00:00
csv encoding: modernize Go documentation 2023-09-08 19:04:28 +00:00
gob encoding: modernize Go documentation 2023-09-08 19:04:28 +00:00
hex encoding: modernize Go documentation 2023-09-08 19:04:28 +00:00
json encoding/json: use reflect.Value.IsZero 2023-10-18 20:00:40 +00:00
pem encoding: modernize Go documentation 2023-09-08 19:04:28 +00:00
xml encoding/xml: reject XML declaration after start of document 2024-02-22 22:50:20 +00:00
encoding.go encoding: document when marshaling methods can be added 2023-05-23 19:43:37 +00:00