Skip to content

Commit

Permalink
fix #468: prettify own properties only
Browse files Browse the repository at this point in the history
  • Loading branch information
amitguptagwl committed May 28, 2022
1 parent 383b836 commit 0721d1d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions spec/langbarrier_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

const {XMLParser, XMLBuilder, XMLValidator} = require("../src/fxp");

describe("XMLParser", function() {

it("should parse <constructor> ", function(){
const xmlData = `<root><other /><constructor /></root>`;
const expected = { root: { other: '', constructor: '' } };

const parser = new XMLParser({preserveOrder:false});
const result = parser.parse(xmlData);
// console.log(result);
expect(result).toEqual(expected);
//expect(result.replace(/\s+/g, "")).to.deep.equal(XMLdata.replace(/\s+/g, ""));
});
});
4 changes: 2 additions & 2 deletions src/xmlparser/node2json.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ function compress(arr, options, jPath){
else val = "";
}

if(compressedObj[property] !== undefined) {
if(compressedObj[property] !== undefined && compressedObj.hasOwnProperty(property)) {
if(!Array.isArray(compressedObj[property])) {
compressedObj[property] = [ compressedObj[property] ];
compressedObj[property] = [ compressedObj[property] ];
}
compressedObj[property].push(val);
}else{
Expand Down

0 comments on commit 0721d1d

Please sign in to comment.