Skip to content

Commit

Permalink
Merge branch '#52' into master. fixed #51
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengchun committed Mar 1, 2021
2 parents 9367e2f + f1467a4 commit e73954f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion node.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func outputXML(buf *bytes.Buffer, n *Node, preserveSpaces bool) {
return
case CharDataNode:
buf.WriteString("<![CDATA[")
xml.EscapeText(buf, []byte(n.sanitizedData(preserveSpaces)))
buf.WriteString(n.Data)
buf.WriteString("]]>")
return
case CommentNode:
Expand Down
10 changes: 10 additions & 0 deletions node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,13 @@ func TestOutputXMLWithSpaceOverwrittenToDefault(t *testing.T) {
}
t.Log(n.OutputXML(false))
}


func TestOutputXMLWithXMLInCDATA(t *testing.T) {
s := `<?xml version="1.0" encoding="utf-8"?><node><![CDATA[<greeting>Hello, world!</greeting>]]></node>`
doc, _ := Parse(strings.NewReader(s))
t.Log(doc.OutputXML(false))
if doc.OutputXML(false) != s {
t.Errorf("the outputted xml escaped CDATA section")
}
}

0 comments on commit e73954f

Please sign in to comment.