Skip to content

Commit

Permalink
Fixing issue dylang#36 and adding test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Malton committed Feb 23, 2018
1 parent f926136 commit c2ce4ce
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ function resolve(data, indent, indent_count) {
}
} else {
//string
content.pop();
if (content[content.length - 1] === '' || content[content.length - 1] === '\n') {
content.pop();
}
isStringContent=true;
content.push(escapeForXML(value));
}
Expand Down
26 changes: 26 additions & 0 deletions test/xml.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,29 @@ test('xml declaration options', t => {
t.is(xml([{a: 'test'}], {declaration: true, indent: '\n'}), '<?xml version="1.0" encoding="UTF-8"?>\n<a>test</a>');
t.is(xml([{a: 'test'}], {}), '<a>test</a>');
});

test('supports multiple mixed data in signle list', t => {
t.is(xml([{ toys: [{
_attr: {
decade: '80s',
locale: 'US'
}
}, {
toy: [{
_attr: {
decade: '70s',
locale: 'CA'
}
},
'Transformers',
{
toya: [{
_attr: {
knowing: 'half the battle'
}
}, 'GI Joe']
},
' and the A-team'
]
}]}]), '<toys decade="80s" locale="US"><toy decade="70s" locale="CA">Transformers<toya knowing="half the battle">GI Joe</toya> and the A-team</toy></toys>')
})

0 comments on commit c2ce4ce

Please sign in to comment.