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
This commit is contained in:
parent
239666cd73
commit
6d2ac307bb
@ -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