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.5k stars 302 forks source link

Fix: Valid DTD declerations causing "Invalid DOCTYPE" error & Allow angle brackets within comments in DOCTYPE #467

Closed Hati- closed 2 years ago

Hati- commented 2 years ago

When I was trying to parse a XML containing attribute list declarations the parser threw the error "Invalid DOCTYPE". I figured that readDocType(...) wasn't aware of attribute list (<!ATTLIST>) and notation (<!NOTATION>) declarations, which causes the parser to throw an error despite them being valid.

Edit: Later when I was trying to parse another XML I noticed that that the parser could bug out if there's a < (left angle bracket) within a comment, or throw the error "Invalid XML comment in DOCTYPE" if there's a > (right angle bracket) within a comment. I've included a fix for this too in this PR. I also made the string "--" (double-hyphen) prohibited within comments to respect the XML specifications.

Purpose / Goal

Type

Please mention the type of PR

Note : Please ensure that you've read contribution guidelines before raising this PR. If your PR is in progress, please prepend [WIP] in PR title. Your PR will be reviewed when [WIP] will be removed from the PR title.

Bookmark this repository for further updates.

Benchmark

Before

$ git checkout master
Already on 'master'
Your branch is up to date with 'origin/master'.

fast-xml-parser/benchmark (master)
$ node ./XmlParser.js 
Running Suite: XML Parser benchmark
fxp v3 : 48925.42004066759 requests/second
fxp : 32984.85177084433 requests/second
fxp - preserve order : 36796.17289188007 requests/second
xmlbuilder2 : 12489.23037965013 requests/second
xml2js  : 8390.77788439448 requests/second

After

$ git checkout patch-doctype-decl 
Switched to branch 'patch-doctype-decl'
Your branch is up to date with 'origin/patch-doctype-decl'.

fast-xml-parser/benchmark (patch-doctype-decl)
$ node ./XmlParser.js
Running Suite: XML Parser benchmark
fxp v3 : 48470.96001554136 requests/second
fxp : 33241.64972804925 requests/second
fxp - preserve order : 35427.0501592926 requests/second
xmlbuilder2 : 12335.001518949128 requests/second
xml2js  : 8274.55732009545 requests/second
coveralls commented 2 years ago

Coverage Status

Coverage decreased (-0.08%) to 98.491% when pulling e102792310cd7c47d8485b3055d91f7e311bc9b4 on Hati-:patch-doctype-decl into 383b836b1bdb076fd85e744f41a5b2bc6a6e8466 on NaturalIntelligence:master.

amitguptagwl commented 2 years ago

Can you please add a sample test for this code?

AScarberry commented 2 years ago

Bump. @Hati- This DTD functionality would be much appreciated.

amitguptagwl commented 2 years ago

These changes are adopted in v4.0.9. So closing this PR