Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Correctly handle empty CData tag and add more test cases.

  • Loading branch information...
commit 07e497ce46d93a3df033366ff970819b668b1949 1 parent f43825d
@Kami Kami authored
Showing with 20 additions and 6 deletions.
  1. +1 −0  lib/elementtree.js
  2. +19 −6 tests/test-simple.js
View
1  lib/elementtree.js
@@ -492,6 +492,7 @@ function _serialize_xml(write, elem, encoding, qnames, namespaces, indent, inden
write(sprintf("<?%s?>", _escape_cdata(text, encoding)));
}
else if (tag === CData) {
+ text = text || '';
write(sprintf("<![CDATA[%s]]>", text));
}
else {
View
25 tests/test-simple.js
@@ -316,11 +316,24 @@ exports['test_remove'] = function(test, assert) {
};
exports['test_cdata_write'] = function(test, assert) {
- var root = Element('root');
- root.append(et.CData('if(0>1) then true;'));
- var etree = new ElementTree(root);
- var xml = etree.write({'xml_declaration': false});
- assert.equal(xml, '<root><![CDATA[if(0>1) then true;]]></root>');
+ var root, etree, xml, values, value, i;
- test.finish();
+ values = [
+ 'if(0>1) then true;',
+ '<test1>ponies hello</test1>',
+ ''
+ ];
+
+ for (i = 0; i < values.length; i++) {
+ value = values[i];
+
+ root = Element('root');
+ root.append(et.CData(value));
+ etree = new ElementTree(root);
+ xml = etree.write({'xml_declaration': false});
+
+ assert.equal(xml, sprintf('<root><![CDATA[%s]]></root>', value));
+ }
+
+ test.finish();
};
Please sign in to comment.
Something went wrong with that request. Please try again.