Skip to content

Instantly share code, notes, and snippets.

@talee
Last active August 15, 2016 23:32
Show Gist options
  • Save talee/07cfa2e6123ec8e1f2548d469dedb2e7 to your computer and use it in GitHub Desktop.
Save talee/07cfa2e6123ec8e1f2548d469dedb2e7 to your computer and use it in GitHub Desktop.
Hyphen in CDATA creates more nodes instead of a single text node.
(function(){var parser=new DOMParser();var expectedContent='hello-world';var result=parser.parseFromString('<div><![CDATA['+expectedContent+']]></div>','text/xml').firstChild.firstChild.data;if(result!=expectedContent)console.log('FAIL');else console.log('SUCCESS');console.log('result:',result);})()
(function(){
var parser = new DOMParser();
var expectedContent = 'hello-world';
var result = parser.parseFromString('<div><![CDATA[' + expectedContent + ']]></div>','text/xml').firstChild.firstChild.data;
if (result != expectedContent) {
console.log('FAIL');
} else {
console.log('SUCCESS');
}
console.log('result:',result);
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment