Skip to content

Commit

Permalink
Serialize "]]>" in text nodes correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
heycam committed Aug 1, 2012
1 parent 7b072e9 commit 22fff92
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ function serializeToString(node,buf){
case ATTRIBUTE_NODE:
return buf.push(' ',node.name,'="',node.value.replace(/[<&"]/g,_xmlEncoder),'"')
case TEXT_NODE:
return buf.push(node.data.replace(/[<&]/g,_xmlEncoder));
return buf.push(node.data.replace(/[<&]/g,_xmlEncoder).replace(/\]\]>/g,']]&gt;'));
case CDATA_SECTION_NODE:
return buf.push( '<![CDATA[',node.data,']]>');
case COMMENT_NODE:
Expand Down
1 change: 1 addition & 0 deletions test/dom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ require('./element');
require('./level3');
require('./clone');
require('./attr');
require('./serializer');
10 changes: 10 additions & 0 deletions test/dom/serializer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var wows = require('vows');
var DOMParser = require('xmldom').DOMParser;

wows.describe('XML Serializer').addBatch({
'text node containing "]]>"': function() {
var doc = new DOMParser().parseFromString('<test/>', 'text/xml');
doc.documentElement.appendChild(doc.createTextNode('hello ]]> there'));
console.assert(doc.documentElement.firstChild.toString() == 'hello ]]&gt; there');
}
}).run();

0 comments on commit 22fff92

Please sign in to comment.