From 1ab44ea837eff59305bd11f0e1a1e542e7c3e79f Mon Sep 17 00:00:00 2001 From: Marek Kubica Date: Tue, 22 Aug 2017 09:36:11 +0200 Subject: [PATCH] Revert "Empty strings now returns error cause its not valid XML" This reverts commit b9b44e08e13278d0f81d46d0316d728e96d6352e. --- lib/parser.js | 4 ++-- package.json | 2 +- src/parser.coffee | 4 ++-- test/parser.test.coffee | 7 ++----- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/parser.js b/lib/parser.js index 4be9cddf..9e8261eb 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -310,8 +310,8 @@ try { str = str.toString(); if (str.trim() === '') { - this.emit('error', new Error("Empty string is not valid XML")); - return; + this.emit("end", null); + return true; } str = bom.stripBOM(str); if (this.options.async) { diff --git a/package.json b/package.json index 2e2ee37d..33b53ec7 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "json" ], "homepage": "https://github.com/Leonidas-from-XIV/node-xml2js", - "version": "0.4.18", + "version": "0.4.19", "author": "Marek Kubica (https://xivilization.net)", "contributors": [ "maqr (https://github.com/maqr)", diff --git a/src/parser.coffee b/src/parser.coffee index e3e3cc62..8a375197 100644 --- a/src/parser.coffee +++ b/src/parser.coffee @@ -237,8 +237,8 @@ class exports.Parser extends events.EventEmitter try str = str.toString() if str.trim() is '' - @emit 'error', new Error "Empty string is not valid XML" - return + @emit "end", null + return true str = bom.stripBOM str if @options.async diff --git a/test/parser.test.coffee b/test/parser.test.coffee index 238ebc46..6d531d56 100644 --- a/test/parser.test.coffee +++ b/test/parser.test.coffee @@ -254,11 +254,8 @@ module.exports = 'test empty tag result specified null': skeleton(emptyTag: null, (r) -> equ r.sample.emptytest[0], null) - 'test invalid empty XML file': (test) -> - x2js = new xml2js.Parser() - x2js.parseString '', (err, r) -> - assert.notEqual err, null - test.finish() + 'test invalid empty XML file': skeleton(__xmlString: ' ', (r) -> + equ r, null) 'test enabled normalizeTags': skeleton(normalizeTags: true, (r) -> console.log 'Result object: ' + util.inspect r, false, 10