diff --git a/src/parser.coffee b/src/parser.coffee index eb19c5b0..bec43e01 100644 --- a/src/parser.coffee +++ b/src/parser.coffee @@ -133,7 +133,7 @@ class exports.Parser extends events s = stack[stack.length - 1] # remove the '#' key altogether if it's blank if obj[charkey].match(/^\s*$/) and not cdata - emptyStr = obj[charkey] + emptyStr = if @options.trim then obj[charkey].trim() else obj[charkey] delete obj[charkey] else obj[charkey] = obj[charkey].trim() if @options.trim diff --git a/test/parser.test.coffee b/test/parser.test.coffee index f2758759..f749f37e 100644 --- a/test/parser.test.coffee +++ b/test/parser.test.coffee @@ -257,6 +257,9 @@ module.exports = 'test text no trimming, no normalize': skeleton(trim: false, normalize: false, (r) -> equ r.sample.whitespacetest[0]._, '\n Line One\n Line Two\n ') + 'test trimming on empty tag with whitespace': skeleton(trim: true, explicitArray: false, (r) -> + equ r.sample.emptytestanother, '') + 'test enabled root node elimination': skeleton(__xmlString: '', explicitRoot: false, (r) -> console.log 'Result object: ' + util.inspect r, false, 10 assert.deepEqual r, '') @@ -599,7 +602,7 @@ module.exports = 'test valueProcessors key param': skeleton(valueProcessors: [replaceValueByName], (r)-> console.log 'Result object: ' + util.inspect r, false, 10 equ r.sample.valueProcessTest[0], 'valueProcessTest') - + 'test parseStringPromise parsing': (test) -> x2js = new xml2js.Parser() readFilePromise(fileName).then (data) -> @@ -610,7 +613,7 @@ module.exports = test.finish() .catch (err) -> test.fail('Should not error') - + 'test parseStringPromise with bad input': (test) -> x2js = new xml2js.Parser() x2js.parseStringPromise("< a moose bit my sister>").then (r) -> @@ -640,7 +643,7 @@ module.exports = test.finish() .catch (err) -> test.fail('Should not error') - + 'test global parseStringPromise with bad input': (test) -> xml2js.parseStringPromise("< a moose bit my sister>").then (r) -> test.fail('Should fail')