diff --git a/dom.js b/dom.js
index f79a561..497978d 100644
--- a/dom.js
+++ b/dom.js
@@ -951,7 +951,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,']]'+_xmlEncoder('>')));
case CDATA_SECTION_NODE:
return buf.push( '');
case COMMENT_NODE:
diff --git a/test/dom/serializer.js b/test/dom/serializer.js
index 73d86ad..81490dc 100644
--- a/test/dom/serializer.js
+++ b/test/dom/serializer.js
@@ -2,10 +2,20 @@ var wows = require('vows');
var DOMParser = require('xmldom').DOMParser;
wows.describe('XML Serializer').addBatch({
+ 'text node containing ">"': function() {
+ var doc = new DOMParser().parseFromString('', 'text/xml');
+ doc.documentElement.appendChild(doc.createTextNode('hello> there'));
+ console.assert(doc.documentElement.firstChild.toString() == 'hello> there',doc.documentElement.firstChild.toString());
+ },
+ 'text node containing "<]]>"': function() {
+ var doc = new DOMParser().parseFromString('', 'text/xml');
+ doc.documentElement.appendChild(doc.createTextNode(' there'));
+ console.assert(doc.documentElement.firstChild.toString() == '<hello ]]> there',doc.documentElement.firstChild.toString());
+ },
'text node containing "]]>"': function() {
var doc = new DOMParser().parseFromString('', 'text/xml');
doc.documentElement.appendChild(doc.createTextNode('hello ]]> there'));
- console.assert(doc.documentElement.firstChild.toString() == 'hello ]]> there',doc.documentElement.firstChild.toString());
+ console.assert(doc.documentElement.firstChild.toString() == 'hello ]]> there',doc.documentElement.firstChild.toString());
},
'