diff --git a/dom.js b/dom.js index 18a7719..eac4c32 100644 --- a/dom.js +++ b/dom.js @@ -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,']]>')); case CDATA_SECTION_NODE: return buf.push( ''); case COMMENT_NODE: diff --git a/test/dom/index.js b/test/dom/index.js index 3a96f37..201a0b0 100644 --- a/test/dom/index.js +++ b/test/dom/index.js @@ -2,3 +2,4 @@ require('./element'); require('./level3'); require('./clone'); require('./attr'); +require('./serializer'); diff --git a/test/dom/serializer.js b/test/dom/serializer.js new file mode 100644 index 0000000..a885286 --- /dev/null +++ b/test/dom/serializer.js @@ -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('', 'text/xml'); + doc.documentElement.appendChild(doc.createTextNode('hello ]]> there')); + console.assert(doc.documentElement.firstChild.toString() == 'hello ]]> there'); + } +}).run();