Skip to content

Normalize XML whitespace and preserve processing instruction data - #10

Merged
Clickin merged 2 commits into
masterfrom
fix/xml-whitespace-w3c-output
Nov 16, 2026
Merged

Clickin merged 2 commits into
masterfrom
fix/xml-whitespace-w3c-output

Conversation

@Clickin

@Clickin Clickin commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

Readers and the converter returned raw line endings and literal attribute whitespace. Processing instruction data also lost trailing whitespace. This change:

  • Normalizes \r\n and \r to \n in parsed content, including CDATA and processing instructions.
  • Replaces literal tabs and line breaks in attribute and namespace values with spaces while preserving numeric character references.
  • Preserves trailing whitespace in processing instruction data.
  • Skips replacement when a value has no characters requiring normalization.
  • Compares supported W3C test cases with their canonical output, in addition to checking whether parsing succeeds or fails.

Fixes #9

Validation

  • Unit tests: 678 passed, including sync, async, chunked input, converter, and processing instruction regression cases.
  • W3C XML test suite: 805 passed, including 111 canonical output comparisons. The existing gate skips 203 cases; another 197 canonical output comparisons are skipped because they require unsupported DTD processing.
  • Package build passed.
  • Local Node.js 26.13.1 benchmark: skipping unnecessary replacement improved throughput by 9–17% on two inputs without normalization characters, compared with unconditional replacement. A synthetic whitespace-heavy input was 2–3% slower.

Compare supported W3C canonical outputs and preserve processing instruction data.
@Clickin Clickin changed the title Fix XML whitespace normalization and check W3C outputs Normalize XML whitespace and preserve processing instruction data Nov 16, 2026

@Clickin Clickin left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolves #9

@Clickin
Clickin merged commit 74aa476 into master Nov 16, 2026
3 checks passed
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.

Reader does not normalize \r\n/\r line endings or literal whitespace in attribute values (XML 1.0 §2.11, §3.3.3)

1 participant