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.43k stars 297 forks source link

Don't escape entities in CDATA sections #633

Closed wackbyte closed 5 months ago

wackbyte commented 5 months ago

Purpose / Goal

Changes the parsing of CDATA sections to not escape entities.

In other words:

I also added a new test so that this behavior can be tested on its own.

Please note that I did not attempt to avoid any breaking changes here as the issue suggested, but if it is desired, I would be happy to gate this fix behind a new option.

The contents of a CDATA section will also now be run through tagValueProcessor even when the cdataPropName option is provided. I am unsure as to if this inconsistency was intentional (the code that would have made it consistent seems to have been commented out a while ago), so if that is considered an unrelated change, I would also be happy to split it out into a separate PR.

Closes #632.

Performance tests

Before:

fxp v3 : 57564.501862728255 requests/second
fxp : 32731.178545462913 requests/second
fxp - preserve order : 35714.0221273455 requests/second
xmlbuilder2 : 15299.516192662688 requests/second
xml2js  : 18881.74875804895 requests/second

After:

fxp v3 : 57721.92080194106 requests/second
fxp : 36231.444954502214 requests/second
fxp - preserve order : 39372.370501577694 requests/second
xmlbuilder2 : 15294.661359575506 requests/second
xml2js  : 18533.786914067532 requests/second

Type

Please mention the type of PR

amitguptagwl commented 5 months ago

Thanks for you PR. let me check

coveralls commented 5 months ago

Coverage Status

coverage: 98.251% (+0.004%) from 98.247% when pulling 66384d116e5f2316fa0100170869e0f570756118 on wackbyte:cdata into 291fe7380206f20355abc971946830dbf72d07f0 on NaturalIntelligence:master.