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

Malformed xml not detected in callback #408

Open
GiordanoArman opened this issue Nov 8, 2017 · 3 comments
Open

Malformed xml not detected in callback #408

GiordanoArman opened this issue Nov 8, 2017 · 3 comments

Comments

@GiordanoArman
Copy link

Hi, I am using parseString to parse a string that looks like this:

<Transaction /> <Transaction /> </confirmation>

using code that looks like this

parseString(xml, function (err, res) {});

A malformed xml error is thrown, but only after the callback is triggered and the err variable is null and the res variable is an object containing Transaction tag data.

Wouldn't it be better to get the error in the callback?

@Leonidas-from-XIV
Copy link
Owner

Wouldn't it be better to get the error in the callback?

I agree, this definitely should happen! Error handling is currently extremely bad.

@jcsahnwaldt
Copy link
Contributor

See #67

@jcsahnwaldt
Copy link
Contributor

Test code to reproduce issue:

const xml2js = require('xml2js');
let xml = `<Transaction /> <Transaction /> </confirmation>`;
try {
  xml2js.parseString(xml, (err, res) => {
    console.log('callback err:');
    console.log(err);
    console.log('callback res:');
    console.log(res);
  });
}
catch (err) {
  console.log('caught err:');
  console.log(err);
}

Output (paths in stacktrace sanitized):

callback err:
null
callback res:
{ Transaction: '' }
caught err:
Error: Unmatched closing tag: confirmation
Line: 0
Column: 47
Char: >
    at error (./node_modules/sax/lib/sax.js:651:10)
    at strictFail (./node_modules/sax/lib/sax.js:677:7)
    at closeTag (./node_modules/sax/lib/sax.js:879:7)
    at SAXParser.write (./node_modules/sax/lib/sax.js:1436:13)
    at Parser.exports.Parser.Parser.parseString (./node_modules/xml2js/lib/parser.js:322:31)
    at Parser.parseString (./node_modules/xml2js/lib/parser.js:5:59)
    at Object.exports.parseString (./node_modules/xml2js/lib/parser.js:354:19)
    at Object.<anonymous> (./test.js:4:10)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)

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