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

Parsing doesn't error on certain invalid xml. #41

Open
emorris00 opened this issue Mar 31, 2022 · 1 comment
Open

Parsing doesn't error on certain invalid xml. #41

emorris00 opened this issue Mar 31, 2022 · 1 comment

Comments

@emorris00
Copy link

There are 2 scenarios I have found where the parser does not throw an error even though the xml is invalid.

  1. root level elements without a close tag that aren't marked as a noChildNodes element
parse("<a><b></b>")
// returns
// [
//   {
//     tagName: 'a',
//     attributes: {},
//     children: [ { tagName: 'b', attributes: {}, children: [] } ]
//   }
// ]
  1. root level orphaned close tags (stops parsing after the first one encountered)
parse("</a><b></b>")
// returns
// []

parse("<a></a></b><c></c>")
// returns
// [ { tagName: 'a', attributes: {}, children: [] } ]

Technically there is a third where it doesn't error if there is more than one root element ex. <a></a><a></a> but I am assuming that is intended behavior so it can parse xml fragments. Maybe there should be an option to toggle whether to parse as a fragment or not? Either way this one isn't a big deal because it is very easy to check after parsing if there are multiple root elements.

@TobiasNickel
Copy link
Owner

yes, I know, this is on purpose. This library skip some checks. just to be faster. if you need a more standard compliant parser, I recommend parse5.

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

2 participants