fix: decode Uint8Array XML input as UTF-8 - #875
Open
emme1t wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Validation
npm test: 332 specs, zero failures, two existing pending specs. Original HEAD: 325 specs, zero failures, two pending.npm run test-types: passing.import.meta, which needs a newer parser setting than the repository's ES2015 configuration; lint passes for that file withecmaVersion: 2022and the ES6 environment enabled.git diff --check: passing.node benchmark/XmlParser.mjsbefore/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.