Skip to content

Commit f12c64b

Browse files
committed
Bugfix: early ending CDATA
1 parent 1795b03 commit f12c64b

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

xml/util.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ func EscapeAttrVal(buf *[]byte, b []byte) []byte {
7575

7676
// EscapeCDATAVal returns the escaped text bytes.
7777
func EscapeCDATAVal(buf *[]byte, cdata []byte) ([]byte, bool) {
78+
if len(cdata) < len("<![CDATA[]]>") {
79+
return cdata, false
80+
}
7881
b := cdata[9 : len(cdata)-3]
7982
n := 0
8083
for i := 0; i < len(b); i++ {

xml/util_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ func TestCDATAVal(t *testing.T) {
4444
assertCDATAVal(t, "<![CDATA[&]]>", "&amp;")
4545
assertCDATAVal(t, "<![CDATA[&&&&]]>", "<![CDATA[&&&&]]>")
4646
assertCDATAVal(t, "<![CDATA[ a ]]>", " a ")
47+
assertCDATAVal(t, "<![CDATA[", "<![CDATA[")
4748
}

0 commit comments

Comments
 (0)