aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/xml/xml_test.go
diff options
context:
space:
mode:
authorConstantin Konstantinidis <constantinkonstantinidis@gmail.com>2018-04-15 11:26:32 +0200
committerGopher Robot <gobot@golang.org>2022-11-09 03:01:28 +0000
commitf13849a7af4c058caa6af14f7d3f9aa81982c124 (patch)
tree6e67cfdb501e6df5f42b38a54fce2deef2376ce6 /src/encoding/xml/xml_test.go
parentb459166219b77857dc6d9366366b015d84e17bbe (diff)
downloadgo-f13849a7af4c058caa6af14f7d3f9aa81982c124.tar.xz
encoding/xml: error when closing tag does not match opening tag
Comparing opening and closing tag is done using the prefix when available. Documentation states that Token returns URI in the Space part of the Name. Translation has been moved for the End tag before the namespace is removed from the stack. After closing a tag using a namespace, the valid namespace must be taken from the opening tag. Tests added. Fixes #20685 Change-Id: I4d90b19f7e21a76663f0ea1c1db6c6bf9fd2a389 Reviewed-on: https://go-review.googlesource.com/c/go/+/107255 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/encoding/xml/xml_test.go')
-rw-r--r--src/encoding/xml/xml_test.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/encoding/xml/xml_test.go b/src/encoding/xml/xml_test.go
index 15c5a7492f..e20dc781a1 100644
--- a/src/encoding/xml/xml_test.go
+++ b/src/encoding/xml/xml_test.go
@@ -1059,6 +1059,41 @@ func TestIssue12417(t *testing.T) {
}
}
+func TestIssue20685(t *testing.T) {
+ testCases := []struct {
+ s string
+ ok bool
+ }{
+ {`<x:book xmlns:x="abcd" xmlns:y="abcd"><unclosetag>one</x:book>`, false},
+ {`<x:book xmlns:x="abcd" xmlns:y="abcd">one</x:book>`, true},
+ {`<x:book xmlns:x="abcd" xmlns:y="abcd">one</y:book>`, false},
+ {`<x:book xmlns:y="abcd" xmlns:x="abcd">one</y:book>`, false},
+ {`<x:book xmlns:x="abcd">one</y:book>`, false},
+ {`<x:book>one</y:book>`, false},
+ {`<xbook>one</ybook>`, false},
+ }
+ for _, tc := range testCases {
+ d := NewDecoder(strings.NewReader(tc.s))
+ var err error
+ for {
+ _, err = d.Token()
+ if err != nil {
+ if err == io.EOF {
+ err = nil
+ }
+ break
+ }
+ }
+ if err != nil && tc.ok {
+ t.Errorf("%q: Closing tag with namespace : expected no error, got %s", tc.s, err)
+ continue
+ }
+ if err == nil && !tc.ok {
+ t.Errorf("%q: Closing tag with namespace : expected error, got nil", tc.s)
+ }
+ }
+}
+
func tokenMap(mapping func(t Token) Token) func(TokenReader) TokenReader {
return func(src TokenReader) TokenReader {
return mapper{