Skip to content

Commit

Permalink
fix: emit CDATA on empty CDATA section too
Browse files Browse the repository at this point in the history
  • Loading branch information
lddubeau committed Jul 10, 2018
1 parent 285d859 commit 95d192f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 1 addition & 3 deletions lib/saxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -986,9 +986,7 @@ class SaxesParser {
sCDataEnding2(chunkState) {
const c = this.getChar(chunkState);
if (c === ">") {
if (this.cdata) {
this.emitNode("oncdata", this.cdata);
}
this.emitNode("oncdata", this.cdata);
this.cdata = "";
this.state = S_TEXT;
}
Expand Down
3 changes: 2 additions & 1 deletion test/cdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

require(".").test({
name: "cdata",
xml: "<r><![CDATA[ this is character data  ]]></r>",
xml: "<r><![CDATA[ this is character data  ]]><![CDATA[]]></r>",
expect: [
["opentagstart", { name: "r", attributes: {} }],
["opentag", { name: "r", attributes: {}, isSelfClosing: false }],
["cdata", " this is character data  "],
["cdata", ""],
["closetag", "r"],
],
});

0 comments on commit 95d192f

Please sign in to comment.