diff --git a/.changes/next-release/bugfix-XML-c6eb8219.json b/.changes/next-release/bugfix-XML-c6eb8219.json new file mode 100644 index 0000000000..5e4e3c0f96 --- /dev/null +++ b/.changes/next-release/bugfix-XML-c6eb8219.json @@ -0,0 +1,5 @@ +{ + "type": "bugfix", + "category": "XML", + "description": "Fixed an array equality bug in the Node.js XML parser" +} \ No newline at end of file diff --git a/lib/xml/node_parser.js b/lib/xml/node_parser.js index 9a2a701936..d9626fb533 100644 --- a/lib/xml/node_parser.js +++ b/lib/xml/node_parser.js @@ -139,7 +139,7 @@ function parseUnknown(xml) { // empty object var keys = Object.keys(xml), i; - if (keys.length === 0 || keys === ['$']) { + if (keys.length === 0 || (keys.length === 1 && keys[0] === '$')) { return {}; } diff --git a/test/xml/parser.spec.js b/test/xml/parser.spec.js index 6527b6fd53..36c5022094 100644 --- a/test/xml/parser.spec.js +++ b/test/xml/parser.spec.js @@ -36,6 +36,13 @@ return expect(data).to.eql({}); }); }); + it('returns an empty object from an empty document with attributes', function() { + var xml; + xml = ''; + return parse(xml, rules, function(data) { + return expect(data).to.eql({}); + }); + }); it('returns empty elements as empty string', function() { var xml; xml = '';