[go] encoding/xml : fix closing tag failure

56 views
Skip to first unread message

Constantin Konstantinidis (Gerrit)

unread,
Apr 15, 2018, 5:31:48 AM4/15/18
to Ian Lance Taylor, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Constantin Konstantinidis has uploaded this change for review.

View Change

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.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I4d90b19f7e21a76663f0ea1c1db6c6bf9fd2a389
Gerrit-Change-Number: 107255
Gerrit-PatchSet: 1
Gerrit-Owner: Constantin Konstantinidis <constantinko...@gmail.com>
Gerrit-MessageType: newchange

Constantin Konstantinidis (Gerrit)

unread,
Jun 4, 2018, 10:14:37 AM6/4/18
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Constantin Konstantinidis uploaded patch set #2 to this change.

View 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.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I4d90b19f7e21a76663f0ea1c1db6c6bf9fd2a389
Gerrit-Change-Number: 107255
Gerrit-PatchSet: 2
Gerrit-Owner: Constantin Konstantinidis <constantinko...@gmail.com>
Gerrit-MessageType: newpatchset

Brad Fitzpatrick (Gerrit)

unread,
Jun 4, 2018, 10:42:47 AM6/4/18
to Constantin Konstantinidis, goph...@pubsubhelper.golang.org, Brad Fitzpatrick, golang-co...@googlegroups.com

View Change

1 comment:

To view, visit change 107255. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I4d90b19f7e21a76663f0ea1c1db6c6bf9fd2a389
Gerrit-Change-Number: 107255
Gerrit-PatchSet: 2
Gerrit-Owner: Constantin Konstantinidis <constantinko...@gmail.com>
Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
Gerrit-Comment-Date: Mon, 04 Jun 2018 14:42:44 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment

Constantin Konstantinidis (Gerrit)

unread,
Jun 4, 2018, 10:45:09 AM6/4/18
to goph...@pubsubhelper.golang.org, Brad Fitzpatrick, golang-co...@googlegroups.com

Constantin Konstantinidis uploaded patch set #3 to this change.

View 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.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I4d90b19f7e21a76663f0ea1c1db6c6bf9fd2a389
Gerrit-Change-Number: 107255
Gerrit-PatchSet: 3
Gerrit-Owner: Constantin Konstantinidis <constantinko...@gmail.com>
Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
Gerrit-MessageType: newpatchset

Brad Fitzpatrick (Gerrit)

unread,
Jun 12, 2018, 1:16:19 PM6/12/18
to Constantin Konstantinidis, goph...@pubsubhelper.golang.org, Brad Fitzpatrick, golang-co...@googlegroups.com

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.

View Change

    To view, visit change 107255. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I4d90b19f7e21a76663f0ea1c1db6c6bf9fd2a389
    Gerrit-Change-Number: 107255
    Gerrit-PatchSet: 3
    Gerrit-Owner: Constantin Konstantinidis <constantinko...@gmail.com>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Comment-Date: Tue, 12 Jun 2018 17:16:17 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: No
    Gerrit-MessageType: comment

    Constantin Konstantinidis (Gerrit)

    unread,
    Jul 23, 2022, 2:13:45 AM7/23/22
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Constantin Konstantinidis uploaded patch set #5 to this change.

    View 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.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I4d90b19f7e21a76663f0ea1c1db6c6bf9fd2a389
    Gerrit-Change-Number: 107255
    Gerrit-PatchSet: 5
    Gerrit-Owner: Constantin Konstantinidis <constantinko...@gmail.com>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-MessageType: newpatchset

    Constantin Konstantinidis (Gerrit)

    unread,
    Jul 23, 2022, 2:15:37 AM7/23/22
    to goph...@pubsubhelper.golang.org, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Brad Fitzpatrick.

    View Change

    1 comment:

    • Commit Message:

      • Done

    To view, visit change 107255. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I4d90b19f7e21a76663f0ea1c1db6c6bf9fd2a389
    Gerrit-Change-Number: 107255
    Gerrit-PatchSet: 5
    Gerrit-Owner: Constantin Konstantinidis <constantinko...@gmail.com>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Comment-Date: Sat, 23 Jul 2022 06:15:31 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-MessageType: comment

    Ian Lance Taylor (Gerrit)

    unread,
    Nov 8, 2022, 4:07:00 PM11/8/22
    to Constantin Konstantinidis, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Brad Fitzpatrick, Constantin Konstantinidis.

    View Change

    1 comment:

    To view, visit change 107255. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I4d90b19f7e21a76663f0ea1c1db6c6bf9fd2a389
    Gerrit-Change-Number: 107255
    Gerrit-PatchSet: 5
    Gerrit-Owner: Constantin Konstantinidis <constantinko...@gmail.com>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Attention: Constantin Konstantinidis <constantinko...@gmail.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Comment-Date: Tue, 08 Nov 2022 21:06:54 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Gerrit-MessageType: comment

    Ian Lance Taylor (Gerrit)

    unread,
    Nov 8, 2022, 4:07:15 PM11/8/22
    to Constantin Konstantinidis, Ian Lance Taylor, goph...@pubsubhelper.golang.org, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Brad Fitzpatrick, Constantin Konstantinidis.

    Patch set 6:Run-TryBot +1

    View Change

      To view, visit change 107255. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I4d90b19f7e21a76663f0ea1c1db6c6bf9fd2a389
      Gerrit-Change-Number: 107255
      Gerrit-PatchSet: 6
      Gerrit-Owner: Constantin Konstantinidis <constantinko...@gmail.com>
      Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
      Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Attention: Constantin Konstantinidis <constantinko...@gmail.com>
      Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Comment-Date: Tue, 08 Nov 2022 21:07:09 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      Gerrit-MessageType: comment

      Ian Lance Taylor (Gerrit)

      unread,
      Nov 8, 2022, 5:14:21 PM11/8/22
      to Constantin Konstantinidis, Ian Lance Taylor, goph...@pubsubhelper.golang.org, Gopher Robot, Brad Fitzpatrick, golang-co...@googlegroups.com

      Attention is currently required from: Brad Fitzpatrick, Constantin Konstantinidis, Ian Lance Taylor.

      Patch set 6:Run-TryBot +1Auto-Submit +1Code-Review +2

      View Change

      1 comment:

      To view, visit change 107255. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I4d90b19f7e21a76663f0ea1c1db6c6bf9fd2a389
      Gerrit-Change-Number: 107255
      Gerrit-PatchSet: 6
      Gerrit-Owner: Constantin Konstantinidis <constantinko...@gmail.com>
      Gerrit-Reviewer: Gopher Robot <go...@golang.org>
      Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Reviewer: Ian Lance Taylor <ia...@google.com>
      Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Attention: Constantin Konstantinidis <constantinko...@gmail.com>
      Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Comment-Date: Tue, 08 Nov 2022 22:14:17 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      Gerrit-MessageType: comment

      Michael Knyszek (Gerrit)

      unread,
      Nov 8, 2022, 10:01:23 PM11/8/22
      to Constantin Konstantinidis, Ian Lance Taylor, goph...@pubsubhelper.golang.org, Gopher Robot, Brad Fitzpatrick, golang-co...@googlegroups.com

      Attention is currently required from: Brad Fitzpatrick, Constantin Konstantinidis, Ian Lance Taylor.

      Patch set 6:Code-Review +1

      View Change

        To view, visit change 107255. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: I4d90b19f7e21a76663f0ea1c1db6c6bf9fd2a389
        Gerrit-Change-Number: 107255
        Gerrit-PatchSet: 6
        Gerrit-Owner: Constantin Konstantinidis <constantinko...@gmail.com>
        Gerrit-Reviewer: Gopher Robot <go...@golang.org>
        Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Reviewer: Ian Lance Taylor <ia...@google.com>
        Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
        Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
        Gerrit-Attention: Constantin Konstantinidis <constantinko...@gmail.com>
        Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
        Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Comment-Date: Wed, 09 Nov 2022 03:01:19 +0000

        Gopher Robot (Gerrit)

        unread,
        Nov 8, 2022, 10:01:33 PM11/8/22
        to Constantin Konstantinidis, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Michael Knyszek, Ian Lance Taylor, Brad Fitzpatrick, golang-co...@googlegroups.com

        Gopher Robot submitted this change.

        View Change


        Approvals: Ian Lance Taylor: Run TryBots Ian Lance Taylor: Looks good to me, approved; Run TryBots; Automatically submit change Gopher Robot: TryBots succeeded Michael Knyszek: Looks good to me, but someone else must approve
        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 @@
        Gerrit-PatchSet: 7
        Gerrit-Owner: Constantin Konstantinidis <constantinko...@gmail.com>
        Gerrit-Reviewer: Gopher Robot <go...@golang.org>
        Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Reviewer: Ian Lance Taylor <ia...@google.com>
        Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
        Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
        Gerrit-MessageType: merged
        Reply all
        Reply to author
        Forward
        0 new messages