Skip to content

fix: preserve carriage return characters in CDATA and text nodes#834

Open
kings9527 wants to merge 1 commit into
NaturalIntelligence:masterfrom
kings9527:master
Open

fix: preserve carriage return characters in CDATA and text nodes#834
kings9527 wants to merge 1 commit into
NaturalIntelligence:masterfrom
kings9527:master

Conversation

@kings9527
Copy link
Copy Markdown

Problem

Carriage Return characters () found within parsed XML are incorrectly converted to newline characters (). This happens because the parser globally replaces all sequences in the input XML data before parsing, including those inside CDATA sections and text nodes where they should be preserved.

The problematic line was:

This line was in and even had a TODO comment suggesting it should be removed.

Solution

  • Removed the global replacement line from
  • Added a unit test in to verify that characters are preserved in both CDATA sections and regular text nodes
  • All 315 tests pass with this change (no regressions)

Test Coverage

line1\rline2

Closes #512

Checklist

  • I have read the Contributing guide
  • The changes are minimal and focused
  • All tests pass (315 specs, 0 failures)
  • Added test coverage for the fix

Remove the line that globally replaced \r and \r\n with \n in the input XML data.
This replacement was incorrectly converting carriage returns inside CDATA
sections and text nodes, which should be preserved as-is.

The existing TODO comment even suggested removing this line.

Closes NaturalIntelligence#512

- Removed: xmlData.replace(/\r\n?/g, "\n") from OrderedObjParser.js
- Added unit test in cdata_spec.js to verify \r preservation in CDATA and text nodes
- All 315 tests pass with this change
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

Successfully merging this pull request may close these issues.

Carriage Return characters (\r) are incorrectly replaced with Newline characters (\n)

1 participant