Skip to content

fix: preserve original metadata offsets for CRLF input - #911

Merged
amitguptagwl merged 1 commit into
NaturalIntelligence:masterfrom
Sskift:fix/metadata-original-crlf-offsets
Nov 3, 2026
Merged

amitguptagwl merged 1 commit into
NaturalIntelligence:masterfrom
Sskift:fix/metadata-original-crlf-offsets

Conversation

@Sskift

@Sskift Sskift commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Purpose / Goal

Fixes #910.

With captureMetaData: true, CRLF input currently produces offsets into the normalized string. Slicing the original input with those offsets therefore returns the wrong XML. For example, the value node in <root>\r\n <value>42</value>\r\n</root> starts at 10 and ends at 27, but the parser reports 9 and 26.

Keep normalizing line endings in parsed values, and translate captured start/end positions back to the original input. Record the collapsed CRLF positions only when metadata capture is enabled. Coverage includes declarations, processing instructions, attributes, comments, CDATA, stop nodes, unpaired tags, dropped siblings, and string/Buffer/Uint8Array input.

Type

  • Bug Fix
  • Refactoring / Technology upgrade
  • New Feature

Validation

  • Original parser with the new tests: 6 failures; LF and standalone-CR controls pass.
  • Start/end metadata suites: 19 specs pass.
  • Full npm test: 340 specs, 0 failures, 2 existing pending.
  • Type checks and git diff --check pass.
  • Independent agent validation: 288 parsing cases / 600 metadata checks pass; 132 baseline failures are corrected. A separate forward-scanning oracle agrees for 196,153 UTF-16 boundaries across 21,845 strings.
  • ESLint reproduces the same original-file errors: the configured ES6 parser does not support existing object-spread syntax in OrderedObjParser, and the original metadata spec contains two undeclared-Map reports.

Performance

Ran node benchmark/XmlParser.mjs before and after. Requests/sec (before → after): fxp v3 140393 → 133425; fxp 58385 → 58070; fxp preserve-order 68802 → 66858; xmlbuilder2 31260 → 30162; xml2js 31063 → 38879. These are shared-host Windows observations; the benchmark uses metadata capture disabled.

Prepared with Codex assistance, automated tests, and independent agent review.

@amitguptagwl
amitguptagwl merged commit 3e4cb65 into NaturalIntelligence:master Nov 3, 2026
14 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.

captureMetaData offsets refer to normalized input when XML contains CRLF

2 participants