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

Incorrect error message with xml tags with no names #215

Open
ehoogerbeets opened this issue Aug 6, 2024 · 0 comments
Open

Incorrect error message with xml tags with no names #215

ehoogerbeets opened this issue Aug 6, 2024 · 0 comments

Comments

@ehoogerbeets
Copy link

ehoogerbeets commented Aug 6, 2024

Code:

const convert = require('xml-js');

const xml1 = '<?xml version="1.0" encoding="UTF-8"?><root>This is a <x>tag</x></root>';
const xml2 = '<?xml version="1.0" encoding="UTF-8"?><root>This is a <>tag</></root>';

try {
  const result1 = convert.xml2json(xml1, {compact: true, spaces: 4});
  console.log("Document 1 parsed successfully:", result1);
} catch (e) {
  console.error("Error parsing document 1:", e.message);
}

try {
  const result2 = convert.xml2json(xml2, {compact: true, spaces: 4});
  console.log("Document 2 parsed successfully:", result2);
} catch (e) {
  console.error("Error parsing document 2:", e.message);
}

The second one correctly throws an error, but the error message says "Unmatched closing tag: <x>" even though there is no <x> tag in the document. I think there is some left-over state from parsing the first document, which hints at possibly larger problems. If you only parse the second document without parsing the first one first, then the error is "Unmatched closing tag: <>" which is correct

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

1 participant