Repository navigation
Conversation
…ayBuffer When a Uint8Array that is a view (e.g. from subarray(), or constructed as new Uint8Array(buffer, byteOffset, length)) is stringified as !!binary on the Buffer path, Buffer.from(buf.buffer) wrapped the entire underlying ArrayBuffer, so the emitted base64 covered bytes before the view and beyond its length; parsing back gave the wrong bytes and the wrong count. Pass buf.byteOffset and buf.byteLength to Buffer.from so only the view's bytes are encoded, matching what the toBase64 and btoa paths already do and what Buffer and a full Uint8Array produce. Regression test: stringify(new Uint8Array([9, 9, 0, 1, 2, 255]).subarray(2)) now round-trips to the four bytes of the view instead of all six. Signed-off-by: simpleqt <2015900818@qq.com>
This branch has not been deployed
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.
The
!!binarystringify path calledBuffer.from(buf.buffer), which base64-encodes the whole underlying ArrayBuffer and ignoresbyteOffset/byteLength:stringify(new Uint8Array([9,9,0,1,2,255]).subarray(2), {version:'1.1'})emitted all six bytes, and the document parses back as[9,9,0,1,2,255]instead of[0,1,2,255].Pass
byteOffset/byteLengthtoBuffer.from(src/schema/yaml-1.1/binary.ts:47), matching what thebtoapath in the same function already does.Regression test in
tests/doc/types.tsfails on main528ef30dand passes with this change. Full vitest suite with the json-test-suite/yaml-test-suite submodules: 3414 passed / 0 failed; eslint, prettier andtsc --noEmitclean.