fix: preserve carriage returns inside CDATA#835
Conversation
The 'should normalize carriage returns outside CDATA' test passed on master both with and without the source change, so it guarded no behavior. Keep the 'should preserve carriage returns in CDATA' test, which exercises the actual fix.
|
Thanks for the PR. new line and carriage return were being removed in starting to simplify regex if I remember correctly. But now most of the code is not using regex. So I'm not sure if we need to remove them at all. Will check once |
|
I went through this and I felt that we need 2 more conditions to handle. Current edit suggest to handle CDATA only but the new line problem is real for other tags too like It should by default support CDATA and But this will not be backward comparible. so we'll have to introduce a flag or rather support Expressions But expressions support at the time of traversing not before parsing starts. I think this need to be designed properly. However, @nodable/flexible-xml-parser would be easier to have this feature. |
Fixes #512
Problem
parseXmlnormalizes line endings withxmlData.replace(/\r\n?/g, "\n")at the top ofOrderedObjParser, which also rewrites\rinside CDATA sections. CDATA content must be preserved byte for byte, so a literal carriage return inside CDATA comes back as\n.Fix
Replace the blanket normalization with a CDATA-aware pass that skips CDATA sections (and tags/comments) and normalizes line endings only outside CDATA. Carriage returns inside CDATA are now preserved; everything else still normalizes as before. Edits
src/xmlparser/OrderedObjParser.js(source), not the generated bundle.Tests
Added a regression test ("should preserve carriage returns in CDATA") that fails before the change and passes after, plus a guard test for normalization outside CDATA. Full jasmine suite passes.