]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/xml: allow ]]> in attribute values
authorDemi Marie Obenour <demi@invisiblethingslab.com>
Tue, 3 Sep 2024 01:33:29 +0000 (01:33 +0000)
committerGopher Robot <gobot@golang.org>
Wed, 4 Sep 2024 13:33:11 +0000 (13:33 +0000)
This is permitted by the XML specification.

Fixes #68387

Change-Id: Ic4ab5520a08a5a997f1c3d13c6d5f80c0521e45c
GitHub-Last-Rev: 6d2ac307bbd0ba7d50830ad8b879c00cc3a7242b
GitHub-Pull-Request: golang/go#69197
Reviewed-on: https://go-review.googlesource.com/c/go/+/610056
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/encoding/xml/xml.go
src/encoding/xml/xml_test.go

index 0fe323f7c86afc36e3ac0297e6d9ac2db94575b1..951676d4032fe4244b4c85c187030aefa3808662 100644 (file)
@@ -1004,8 +1004,9 @@ Input:
                }
 
                // <![CDATA[ section ends with ]]>.
-               // It is an error for ]]> to appear in ordinary text.
-               if b0 == ']' && b1 == ']' && b == '>' {
+               // It is an error for ]]> to appear in ordinary text,
+               // but it is allowed in quoted strings.
+               if quote < 0 && b0 == ']' && b1 == ']' && b == '>' {
                        if cdata {
                                trunc = 2
                                break Input
index b2a06a7639702df28cc055fb116916c9fe7aeb08..fc3c15eff1b689c6ed53ae74dcda034db6956923 100644 (file)
@@ -626,6 +626,30 @@ type item struct {
        FieldA string
 }
 
+func TestIssue68387(t *testing.T) {
+       data := `<item b=']]>'/>`
+       dec := NewDecoder(strings.NewReader(data))
+       var tok1, tok2, tok3 Token
+       var err error
+       if tok1, err = dec.RawToken(); err != nil {
+               t.Fatalf("RawToken() failed: %v", err)
+       }
+       if tok2, err = dec.RawToken(); err != nil {
+               t.Fatalf("RawToken() failed: %v", err)
+       }
+       if tok3, err = dec.RawToken(); err != io.EOF || tok3 != nil {
+               t.Fatalf("Missed EOF")
+       }
+       s := StartElement{Name{"", "item"}, []Attr{Attr{Name{"","b"}, "]]>"}}}
+       if !reflect.DeepEqual(tok1.(StartElement), s) {
+               t.Error("Wrong start element")
+       }
+       e := EndElement{Name{"","item"}}
+       if tok2.(EndElement) != e {
+               t.Error("Wrong end element")
+       }
+}
+
 func TestIssue569(t *testing.T) {
        data := `<item><FieldA>abcd</FieldA></item>`
        var i item