NaturalIntelligence / fast-xml-parser

Validate XML, Parse XML and Build XML rapidly without C/C++ based libraries and no callback.
https://naturalintelligence.github.io/fast-xml-parser/
MIT License
2.49k stars 302 forks source link

Error when using '<' and '>' in comment in doctype markup declaration list #530

Open Cwazywierdo opened 1 year ago

Cwazywierdo commented 1 year ago

Description

Trying to parse comments containing '<' or '>' inside the DOCTYPE markup declaration list results in errors. The errors are different depending on whether '<' or '>' was used (or which appears first). This is not an issue if the comment is elsewhere in the file. ### Code and output 1) ```js const xmlStr = `

<!ELEMENT greeting (#PCDATA)> ]>

Hello, world!

`

const parser = new fxparser.XMLParser(); const output = parser.parse(xmlStr);

out:

Uncaught Error: Invalid DOCTYPE readDocType DocTypeReader.js:73 parseXml OrderedObjParser.js:245 parse XMLParser.js:35 DocTypeReader.js:73:26


2)
```js
const xmlStr = `
<!DOCTYPE greeting [
  <!-- > -->
  <!ELEMENT greeting (#PCDATA)>
]>
<greeting>Hello, world!</greeting>
`

const parser = new fxparser.XMLParser();
const output = parser.parse(xmlStr);

out:

Uncaught Error: Invalid XML comment in DOCTYPE
    readDocType DocTypeReader.js:82
    parseXml OrderedObjParser.js:245
    parse XMLParser.js:35
DocTypeReader.js:82:30

Probably not important, but I feel I should note that while the online version still throws errors, the error messages are different. '<' and '>' throw Error: Start tag expected.:1:undefined and Error: char 'E' is not expected.:3:5 respectively.

Would you like to work on this issue?

Bookmark this repository for further updates.

github-actions[bot] commented 1 year ago

I'm glad you find this repository helpful. I'll try to address your issue ASAP. You can watch the repo for new changes or star it.