diff --git a/lib/xml.js b/lib/xml.js index 01a5654..7393c66 100644 --- a/lib/xml.js +++ b/lib/xml.js @@ -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)); } diff --git a/test/xml.test.js b/test/xml.test.js index 845e79d..ccb7909 100644 --- a/test/xml.test.js +++ b/test/xml.test.js @@ -148,3 +148,29 @@ test('xml declaration options', t => { t.is(xml([{a: 'test'}], {declaration: true, indent: '\n'}), '\ntest'); t.is(xml([{a: 'test'}], {}), 'test'); }); + +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' + ] + }]}]), 'TransformersGI Joe and the A-team') +})