Repository navigation
fix(buffer): support latin1/ascii/base64url encodings and honor concat totalLength - #1864
Merged
Merged
Conversation
…t totalLength - Buffer.from/toString accepted 'latin1', 'binary', 'ascii' and 'base64url' labels were either rejected or decoded as UTF-8. Node decodes latin1/binary/ascii as one byte per code unit and accepts base64url without padding. - Add Latin1 and Base64Url encoder variants; 'ascii' decodes masked to 7 bits and encodes like latin1, matching Node. - Buffer.isEncoding now accepts exactly Node's label set. - Buffer.concat(list, totalLength) ignored the remainder of totalLength and returned a short buffer; it now zero-pads like Node. - Blob part number formatting uses ryu-js to match JS ToString.
richarddd
requested changes
Nov 4, 2026
richarddd
left a comment
Collaborator
There was a problem hiding this comment.
Small comment. Also do we use from_str and for_buffer now? this can be confusing
Review feedback: pin the ryu-js version like other workspace deps, and disambiguate the two encoding constructors — from_label (WHATWG Encoding Standard labels, TextDecoder semantics) vs for_buffer (Node.js Buffer encodings).
Contributor
Author
|
Done — pinned ryu-js to "1" and renamed the WHATWG constructor to from_label/from_label_optional so the two entry points read unambiguously: from_label (WHATWG Encoding Standard labels) vs for_buffer (Node.js Buffer encodings). |
richarddd
approved these changes
Nov 4, 2026
3 of 5 tasks
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.
Issue # (if available)
None — found via differential fuzzing of
Bufferencoding andconcatbehavior against Node.js.Description of changes
latin1,binary,asciiandbase64urlencodings.Buffer.from(str, "latin1")decoded the string as UTF-8 (e.g."café"produced 5 bytes instead of 4), andbase64urlwas rejected entirely. NewLatin1andBase64UrlEncodervariants decode/encode one byte per code unit and accept the URL-safe alphabet without padding.asciidecodes masked to 7 bits and encodes likelatin1, matching Node's behavior.Buffer.isEncodingnow accepts exactly the labels Node accepts (e.g.iso-8859-1andwindows-1252are rejected;bufferis kept as the existing LLRT alias).Buffer.concat(list, totalLength)ignored the remainder oftotalLengthand returned a short buffer; it now zero-pads like Node.ryu-jsto matchToStringsemantics.Checklist
tests/unitand/or in Rust for my feature if neededmake fixto format JS and apply Clippy auto fixesmake checktypes/directory (no signature changes)By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.