diff options
| author | Robert Stepanek <robert.stepanek@gmail.com> | 2015-09-05 16:06:43 +0200 |
|---|---|---|
| committer | Nigel Tao <nigeltao@golang.org> | 2015-09-10 01:18:30 +0000 |
| commit | bf2164390bd499145fc712194bb54290effd7e14 (patch) | |
| tree | f0d8c033f95e094cc447640aa4c4ce34851c20da /src/encoding/xml/xml_test.go | |
| parent | da7e9e4fa7a482a2c93ee40b601077ed85606263 (diff) | |
| download | go-bf2164390bd499145fc712194bb54290effd7e14.tar.xz | |
encoding/xml: Return SyntaxError for unmatched root start elements.
Currently, the xml.Decoder's Token routine returns successfully for
XML input that does not properly close root start elements (and any
unclosed descendants). For example, all the following inputs
<root>
<root><foo>
<root><foo></foo>
cause Token to return with nil and io.EOF, indicating a successful
parse.
This change fixes that. It leaves the semantics of RawToken intact.
Fixes #11405
Change-Id: I6f1328c410cf41e17de0a93cf357a69f12c2a9f7
Reviewed-on: https://go-review.googlesource.com/14315
Reviewed-by: Nigel Tao <nigeltao@golang.org>
Diffstat (limited to 'src/encoding/xml/xml_test.go')
| -rw-r--r-- | src/encoding/xml/xml_test.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/encoding/xml/xml_test.go b/src/encoding/xml/xml_test.go index 312a7c98a5..19465d7fb1 100644 --- a/src/encoding/xml/xml_test.go +++ b/src/encoding/xml/xml_test.go @@ -750,3 +750,24 @@ func TestIssue5880(t *testing.T) { t.Errorf("Marshal generated invalid UTF-8: %x", data) } } + +func TestIssue11405(t *testing.T) { + testCases := []string{ + "<root>", + "<root><foo>", + "<root><foo></foo>", + } + for _, tc := range testCases { + d := NewDecoder(strings.NewReader(tc)) + var err error + for { + _, err = d.Token() + if err != nil { + break + } + } + if _, ok := err.(*SyntaxError); !ok { + t.Errorf("%s: Token: Got error %v, want SyntaxError", tc, err) + } + } +} |
