Skip to content

Incorrect error message with xml tags with no names #215

@ehoogerbeets

Description

@ehoogerbeets

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions