From 77adfa09fe814fd45a8949969d16a7146c3c29de Mon Sep 17 00:00:00 2001 From: Andris Reinman Date: Sun, 29 Jul 2012 17:12:15 +0300 Subject: [PATCH] Fixed eternal loop with error emitter --- lib/xml2object.js | 2 +- test/error-test.js | 17 +++++++++++++++++ test/fixture/input02.xml | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/error-test.js create mode 100644 test/fixture/input02.xml diff --git a/lib/xml2object.js b/lib/xml2object.js index cee7a03..1821c0a 100644 --- a/lib/xml2object.js +++ b/lib/xml2object.js @@ -140,7 +140,7 @@ var xml2object = module.exports = function(elements, source) { // Rebroadcast the error and keep going this.saxStream.on("error", function (e) { - this.emit('error', e); + self.emit('error', e); // clear the error and resume this._parser.error = null; diff --git a/test/error-test.js b/test/error-test.js new file mode 100644 index 0000000..2e73dfe --- /dev/null +++ b/test/error-test.js @@ -0,0 +1,17 @@ +var nodeunit = require('nodeunit'); +var path = require('path'); +var xml2object = require('../lib/xml2object'); + +exports.testError = function(test){ + test.expect(1); + + var parser = new xml2object(['dog'], path.normalize(__dirname + '/fixture/input02.xml')); + var found = []; + + parser.on('error', function(error) { + test.ok(error instanceof Error); + test.done(); + }); + + parser.start(); +}; \ No newline at end of file diff --git a/test/fixture/input02.xml b/test/fixture/input02.xml new file mode 100644 index 0000000..b98f033 --- /dev/null +++ b/test/fixture/input02.xml @@ -0,0 +1 @@ +just some invalid xml data \ No newline at end of file