Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid XML parsing fails when async is set to true #232

Closed
fiznool opened this issue Sep 1, 2015 · 2 comments
Closed

Invalid XML parsing fails when async is set to true #232

fiznool opened this issue Sep 1, 2015 · 2 comments

Comments

@fiznool
Copy link
Contributor

fiznool commented Sep 1, 2015

This seems to be a side-effect of #229.

async set to false:

var xml2js = require('xml2js');
var parser = new xml2js.Parser({
  async: false,
});

var invalid_xml = '"some data"';
parser.parseString(invalid_xml, function(err, results){
  console.log("ERRORS: " + err);
  console.log("RESULTS: " + results);
});

yields (as expected):

ERRORS: Error: Non-whitespace before first tag.
Line: 0
Column: 1
Char: "
RESULTS: undefined

However, async set to true:

var xml2js = require('xml2js');
var parser = new xml2js.Parser({
  async: true,
});

var invalid_xml = '"some data"';
parser.parseString(invalid_xml, function(err, results){
  console.log("ERRORS: " + err);
  console.log("RESULTS: " + results);
});

throws an unhandled exception:

ERRORS: Error: Non-whitespace before first tag.
Line: 0
Column: 1
Char: "
RESULTS: undefined
events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: Text data outside of root node.
Line: 0
Column: 2
Char: s
    at error (/home/fiznool/Code/sandbox/xml2js-parse-exception/node_modules/xml2js/node_modules/sax/lib/sax.js:652:8)
    at strictFail (/home/fiznool/Code/sandbox/xml2js-parse-exception/node_modules/xml2js/node_modules/sax/lib/sax.js:675:22)
    at Object.write (/home/fiznool/Code/sandbox/xml2js-parse-exception/node_modules/xml2js/node_modules/sax/lib/sax.js:981:13)
    at Parser.exports.Parser.Parser.processAsync (/home/fiznool/Code/sandbox/xml2js-parse-exception/node_modules/xml2js/lib/xml2js.js:254:41)
    at Immediate._onImmediate (/home/fiznool/Code/sandbox/xml2js-parse-exception/node_modules/xml2js/lib/xml2js.js:7:59)
    at processImmediate [as _immediateCallback] (timers.js:367:17)

I'm guessing this has something to do with the processAsync function causing the error event to be emitted in a new cycle, which isn't caught by the error handler setup in parseString. But I'm not really sure.

@tflanagan
Copy link
Contributor

This is fixed in #240

@Leonidas-from-XIV
Copy link
Owner

Merged #240.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants