Skip to content

fix: decode Uint8Array XML input as UTF-8 - #875

Open
emme1t wants to merge 2 commits into
NaturalIntelligence:masterfrom
emme1t:fix/uint8array-xml-input
Open

fix: decode Uint8Array XML input as UTF-8#875
emme1t wants to merge 2 commits into
NaturalIntelligence:masterfrom
emme1t:fix/uint8array-xml-input

Conversation

@emme1t

@emme1t emme1t commented Sep 12, 2026

Copy link
Copy Markdown

Fixes #874.

Purpose / Goal

Decode plain Uint8Array input as UTF-8 before parsing or validating it. parse(new TextEncoder().encode('<root>hello</root>')) currently returns {} although the public TypeScript overloads accept Uint8Array. With this change it returns { root: 'hello' }.

Node Buffer inputs retain their existing toString() conversion. TextDecoder.decode(view) respects a Uint8Array subview's byte offset and length. The decoder retains a UTF-8 BOM so captured character offsets match string and Buffer input. Tests cover accented text and emoji, subviews, valid and invalid XML with validation enabled, preserved node order, BOM metadata offsets, and UTF-8 Buffer input.

Type

  • Bug Fix
  • Refactoring / Technology upgrade
  • New Feature

Validation

  • Five input-type regression cases failed against the original implementation.
  • Patched input-type suite: eight specs, zero failures.
  • npm test: 332 specs, zero failures, two existing pending specs. Original HEAD: 325 specs, zero failures, two pending.
  • npm run test-types: passing.
  • Source lint passes with the repository configuration. The existing input test uses import.meta, which needs a newer parser setting than the repository's ES2015 configuration; lint passes for that file with ecmaVersion: 2022 and the ES6 environment enabled.
  • git diff --check: passing.
  • Browser bundle smoke test: Chromium 151, with no global Buffer, correctly parses a UTF-8 subview containing accented text, CJK text and emoji with validation enabled, and preserves BOM metadata offsets.
  • node benchmark/XmlParser.mjs before/after: default parsing 27,514 / 30,133 requests per second; preserved order 24,394 / 33,180. Timings vary on this shared machine. An additional seven-round alternating check using the same fixture recorded median paired throughput ratios of 0.988 for strings and 1.002 for Buffers.

Investigated and implemented with OpenAI Codex assistance; reproduction and tests were executed locally.

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.

XMLParser.parse returns an empty object for a plain Uint8Array

1 participant