Constantin Konstantinidis has uploaded this change for review.
encoding/xml : fix closing tag failure
Push/pop of elements name must be done using the eventual prefix together with the tag name.
The operation is moved before the translation of prefix into its URI.
One end element of a test is fixed as expecting the last used namespace is incorrect.
After closing a tag using a namespace, the valid namespace must be taken from the opening tag.
Several tests added.
Fixes #20685
Change-Id: I4d90b19f7e21a76663f0ea1c1db6c6bf9fd2a389
---
M src/encoding/xml/xml.go
M src/encoding/xml/xml_test.go
2 files changed, 39 insertions(+), 4 deletions(-)
diff --git a/src/encoding/xml/xml.go b/src/encoding/xml/xml.go
index 5a51d4c..7df0362 100644
--- a/src/encoding/xml/xml.go
+++ b/src/encoding/xml/xml.go
@@ -318,18 +318,18 @@
}
}
+ d.pushElement(t1.Name) // Pushing the element with its eventual prefix
d.translate(&t1.Name, true)
for i := range t1.Attr {
d.translate(&t1.Attr[i].Name, false)
}
- d.pushElement(t1.Name)
t = t1
case EndElement:
- d.translate(&t1.Name, true)
- if !d.popElement(&t1) {
+ if !d.popElement(&t1) { // Popping the element with its eventual prefix for appropriate comparison
return nil, d.err
}
+ d.translate(&t1.Name, true)
t = t1
}
return t, err
diff --git a/src/encoding/xml/xml_test.go b/src/encoding/xml/xml_test.go
index 7a3511d..f20b867 100644
--- a/src/encoding/xml/xml_test.go
+++ b/src/encoding/xml/xml_test.go
@@ -103,7 +103,7 @@
CharData("\n "),
EndElement{Name{"ns3", "name"}},
CharData("\n"),
- EndElement{Name{"ns2", "body"}},
+ EndElement{Name{"", "body"}}, // ns2 is assigned only because it is the last space when it should have been popped
Comment(" missing final newline "),
}
@@ -798,6 +798,41 @@
}
}
+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{
To view, visit change 107255. To unsubscribe, or for help writing mail filters, visit settings.
Constantin Konstantinidis uploaded patch set #2 to this change.
encoding/xml : fix closing tag failure
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. Several tests added.
Fixes #20685
Change-Id: I4d90b19f7e21a76663f0ea1c1db6c6bf9fd2a389
---
M src/encoding/xml/xml.go
M src/encoding/xml/xml_test.go
2 files changed, 41 insertions(+), 4 deletions(-)
To view, visit change 107255. To unsubscribe, or for help writing mail filters, visit settings.
1 comment:
delete the space before the colon
To view, visit change 107255. To unsubscribe, or for help writing mail filters, visit settings.
Constantin Konstantinidis uploaded patch set #3 to this change.
encoding/xml: fix closing tag failure
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. Several tests added.
Fixes #20685
Change-Id: I4d90b19f7e21a76663f0ea1c1db6c6bf9fd2a389
---
M src/encoding/xml/xml.go
M src/encoding/xml/xml_test.go
2 files changed, 41 insertions(+), 4 deletions(-)
To view, visit change 107255. To unsubscribe, or for help writing mail filters, visit settings.
I discussed these XML changes with Russ and others and it sounds like we want to prioritize these (and JSON) for after Go 1.11 and after vgo. We just didn't have the review bandwidth in this area this cycle and can't accept the risk of regressions this late in Go 1.11. I'm going to mark this for Go 1.12 for now. Sorry.
Constantin Konstantinidis uploaded patch set #5 to this change.
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
---
M src/encoding/xml/xml.go
M src/encoding/xml/xml_test.go
2 files changed, 57 insertions(+), 2 deletions(-)
To view, visit change 107255. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Brad Fitzpatrick.
1 comment:
Commit Message:
delete the space before the colon
Done
To view, visit change 107255. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Brad Fitzpatrick, Constantin Konstantinidis.
1 comment:
Patchset:
RELNOTE=yes
To view, visit change 107255. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Brad Fitzpatrick, Constantin Konstantinidis.
Patch set 6:Run-TryBot +1
Attention is currently required from: Brad Fitzpatrick, Constantin Konstantinidis, Ian Lance Taylor.
Patch set 6:Run-TryBot +1Auto-Submit +1Code-Review +2
1 comment:
Patchset:
Thanks for your patience.
To view, visit change 107255. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Brad Fitzpatrick, Constantin Konstantinidis, Ian Lance Taylor.
Patch set 6:Code-Review +1
Gopher Robot submitted this change.
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 <ia...@golang.org>
Reviewed-by: Ian Lance Taylor <ia...@google.com>
TryBot-Result: Gopher Robot <go...@golang.org>
Auto-Submit: Ian Lance Taylor <ia...@google.com>
Reviewed-by: Michael Knyszek <mkny...@google.com>
Run-TryBot: Ian Lance Taylor <ia...@google.com>
---
M src/encoding/xml/xml.go
M src/encoding/xml/xml_test.go
2 files changed, 64 insertions(+), 2 deletions(-)
diff --git a/src/encoding/xml/xml.go b/src/encoding/xml/xml.go
index 50a91a8..d4509df 100644
--- a/src/encoding/xml/xml.go
+++ b/src/encoding/xml/xml.go
@@ -314,15 +314,14 @@
}
}
+ d.pushElement(t1.Name)
d.translate(&t1.Name, true)
for i := range t1.Attr {
d.translate(&t1.Attr[i].Name, false)
}
- d.pushElement(t1.Name)
t = t1
case EndElement:
- d.translate(&t1.Name, true)
if !d.popElement(&t1) {
return nil, d.err
}
@@ -495,6 +494,8 @@
return false
}
+ d.translate(&t.Name, true)
+
// Pop stack until a Start or EOF is on the top, undoing the
// translations that were associated with the element we just closed.
for d.stk != nil && d.stk.kind != stkStart && d.stk.kind != stkEOF {
diff --git a/src/encoding/xml/xml_test.go b/src/encoding/xml/xml_test.go
index 15c5a74..e20dc78 100644
--- a/src/encoding/xml/xml_test.go
+++ b/src/encoding/xml/xml_test.go
@@ -1059,6 +1059,41 @@