aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/xml/xml_test.go
diff options
context:
space:
mode:
authorAxel Wagner <axel.wagner.hh@googlemail.com>2024-02-14 09:38:46 +0100
committerGopher Robot <gobot@golang.org>2024-02-22 22:50:20 +0000
commit8a0fbd75a54c27ff2ae624ac2775bf752cdbceb4 (patch)
treef2f3db97bf9817ff1d6c148b2fcb27dbba478235 /src/encoding/xml/xml_test.go
parentd892cb496a30ec274ee87f3cd0cf6bb7ac682ab3 (diff)
downloadgo-8a0fbd75a54c27ff2ae624ac2775bf752cdbceb4.tar.xz
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>
Diffstat (limited to 'src/encoding/xml/xml_test.go')
-rw-r--r--src/encoding/xml/xml_test.go2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/encoding/xml/xml_test.go b/src/encoding/xml/xml_test.go
index 4bec4e7f1e..2c985f7c70 100644
--- a/src/encoding/xml/xml_test.go
+++ b/src/encoding/xml/xml_test.go
@@ -1350,10 +1350,12 @@ func TestParseErrors(t *testing.T) {
// Header-related errors.
{`<?xml version="1.1" encoding="UTF-8"?>`, `unsupported version "1.1"; only version 1.0 is supported`},
+ {`<foo><?xml version="1.0"?>`, `XML declaration after start of document`},
// Cases below are for "no errors".
{withDefaultHeader(`<?ok?>`), ``},
{withDefaultHeader(`<?ok version="ok"?>`), ``},
+ {` <?xml version="1.0"?>`, ``},
}
for _, test := range tests {