Open mandrewpowers opened 3 years ago
Updated once I realized I seem to be using the API incorrectly when not passing a callback. This may be a sax problem, but I'm honestly not sure.
Last additional comment:
Noticed if the extra token is an orphaned opening tag such as <root></root><root>
, it is also not detected since the stack seems to clean up even if the stream still has left over token(s).
While I agree that this is surprising, it is not all that unexpected since xml2js aims to parse one item from the string and by the time the </root>
is encountered the tree is finished, so whatever comes afterwards can be ignored (it probably should not be ignored, because that means it accepts invalid XML but I would assume that many JSON parsers also accept {}}
as input only to discard everything after a complete object has been parsed from the input stream.
same issue: first time parseString return an error, for second try i received object with incorrect data . any workarounds?
When parsing this malformed XML,
<root></root></root>
, throughparseString
with and without a callback function I am experiencing different results. With a callback I am seeing{ "root": "" }
and no error, but without the callback an error is thrown synchronously. Although, without a callback and a correctly formatted XML string I don't get the results.Unless I somehow misunderstood the API this seems quite incorrect. I at least expected the callback to receive a populated
err
argument even if I was using the package incorrectly when it throws as I originally expected. The promisified version of course has the same unexpected behavior.Node:
v12.16.1
xml2js:0.4.23
Example: