-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect result from Buffer.from(...).buffer
when using base64url
encoding
#55564
Comments
This might be a similar issue to that of #55422 |
I believe this is intended behavior. The Not accessing the import { Buffer } from 'node:buffer';
import assert from 'node:assert';
const expected = Buffer.from([0x1b, 0x86, 0x66, 0x6b, 0x27, 0xfd, 0x6b, 0x82, 0x8e, 0x90, 0xa1, 0xc1, 0x15, 0xe1, 0xc7, 0x41,
0x11, 0x33, 0x44, 0xc5, 0xbf, 0xe8, 0xc3, 0xd1]);
const actual = Buffer.from('G4Zmayf9a4KOkKHBFeHHQREzRMW_6MPR', 'base64url');
assert.deepStrictEqual(actual, expected); We should probably not allow access to the underlying pooled buffer, to prevent confusions just like this one. |
I didn’t come up with this myself; it’s actually from Bun’s guides, and I thought it was supposed to be a standard way to do so. Most of the time, I can just use |
See the Node.js docs here. It states that the returned 'ArrayBuffer' might not correspond exactly to the 'Buffer'. |
Thanks, I’ll close this since it lines up with the docs. |
Version
v20.18.0
Platform
Subsystem
No response
What steps will reproduce the bug?
When attempting to create an
ArrayBuffer
usingBuffer.from(..., 'base64url').buffer
, the output is incorrect. Instead of the expectedArrayBuffer
, the function produces an unexpectedly largerArrayBuffer
.node -p "Buffer.from('G4Zmayf9a4KOkKHBFeHHQREzRMW_6MPR', 'base64url').buffer"
Result:
FYI: The string
G4Zmayf9a4KOkKHBFeHHQREzRMW_6MPR
is produced byBuffer#toString('base64url')
containing some random bytes.How often does it reproduce? Is there a required condition?
Stable
What is the expected behavior? Why is that the expected behavior?
Should get a correctly-sized
ArrayBuffer
representing thebase64url
decoded string, like Deno does:What do you see instead?
Additional information
No response
The text was updated successfully, but these errors were encountered: