mirror of
https://github.com/golang/go
synced 2024-11-22 05:34:39 -07:00
encoding/xml: allow ]]> in attribute values
This is permitted by the XML specification.
Fixes #68387
Change-Id: Ic4ab5520a08a5a997f1c3d13c6d5f80c0521e45c
GitHub-Last-Rev: 6d2ac307bb
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>
This commit is contained in:
parent
6450a988a7
commit
794b0a0748
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user