diff --git a/lib/bom.js b/lib/bom.js index 11baf75b..511086f9 100644 --- a/lib/bom.js +++ b/lib/bom.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.11.1 +// Generated by CoffeeScript 1.12.4 (function() { "use strict"; exports.stripBOM = function(str) { diff --git a/lib/builder.js b/lib/builder.js index d8f19442..6eedb003 100644 --- a/lib/builder.js +++ b/lib/builder.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.11.1 +// Generated by CoffeeScript 1.12.4 (function() { "use strict"; var builder, defaults, escapeCDATA, requiresCDATA, wrapCDATA, diff --git a/lib/defaults.js b/lib/defaults.js index 112597af..c4ed2cdc 100644 --- a/lib/defaults.js +++ b/lib/defaults.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.11.1 +// Generated by CoffeeScript 1.12.4 (function() { exports.defaults = { "0.1": { diff --git a/lib/parser.js b/lib/parser.js index e72578a5..36c81e14 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -310,8 +310,8 @@ try { str = str.toString(); if (str.trim() === '') { - this.emit("end", null); - return true; + this.emit('error', new Error("Empty string is not valid XML")); + return; } str = bom.stripBOM(str); if (this.options.async) { diff --git a/lib/processors.js b/lib/processors.js index 75f96098..eba05bbb 100644 --- a/lib/processors.js +++ b/lib/processors.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.11.1 +// Generated by CoffeeScript 1.12.4 (function() { "use strict"; var prefixMatch; diff --git a/lib/xml2js.js b/lib/xml2js.js index c063ff53..0e85b9a7 100644 --- a/lib/xml2js.js +++ b/lib/xml2js.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.11.1 +// Generated by CoffeeScript 1.12.4 (function() { "use strict"; var builder, defaults, parser, processors, diff --git a/src/parser.coffee b/src/parser.coffee index 8a375197..e3e3cc62 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 "end", null - return true + @emit 'error', new Error "Empty string is not valid XML" + return str = bom.stripBOM str if @options.async diff --git a/test/parser.test.coffee b/test/parser.test.coffee index 6d531d56..238ebc46 100644 --- a/test/parser.test.coffee +++ b/test/parser.test.coffee @@ -254,8 +254,11 @@ module.exports = 'test empty tag result specified null': skeleton(emptyTag: null, (r) -> equ r.sample.emptytest[0], null) - 'test invalid empty XML file': skeleton(__xmlString: ' ', (r) -> - equ r, null) + 'test invalid empty XML file': (test) -> + x2js = new xml2js.Parser() + x2js.parseString '', (err, r) -> + assert.notEqual err, null + test.finish() 'test enabled normalizeTags': skeleton(normalizeTags: true, (r) -> console.log 'Result object: ' + util.inspect r, false, 10