-
Notifications
You must be signed in to change notification settings - Fork 28.6k
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
Unexpected behavior of Buffer.from( num.toString(16), "hex" ) #21242
Labels
buffer
Issues and PRs related to the buffer subsystem.
feature request
Issues that request new features to be added to Node.js.
Comments
FWIW, this behavior seems documented:
|
Yes, it's the documented behavior. 'hex' has always behaved this way and it's not something we'll change, that would be massively backwards incompatible. |
I think |
orenyomtov
added a commit
to orenyomtov/lodestar
that referenced
this issue
Nov 8, 2023
Related to this "documented behavior" quirk of `Buffer.from`: nodejs/node#21242
nazarhussain
pushed a commit
to ChainSafe/lodestar
that referenced
this issue
Nov 29, 2023
* Fix `hexToBuffer` bug Related to this "documented behavior" quirk of `Buffer.from`: nodejs/node#21242 * Fix lint * Implement in multiple lines
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
buffer
Issues and PRs related to the buffer subsystem.
feature request
Issues that request new features to be added to Node.js.
Info:
Version: v8.10.0
Platform: Windows 10, 64-bit
Subsystem: buffer module: Buffer.from
Code:
Problem:
b == <Buffer ab>
and I expect thatb == <Buffer 0a bc>
Details and explanation:
When calling
Buffer.from( ... , 'hex')
with hex string that have odd number of characters (in case when no leading zero provided) I expect Buffer.from to add leading zero in case of hex encoding, so"1"
will be recognized as"01"
.Use case example:
I expect that in above example I do not have to append on my own leading "0" in case when toString(16) returns odd number of characters.
Other solution I see (instead of fixing
Buffer.from
) is to updatetoString(16)
, but in my opinion fix should implemented insideBuffer.from
.The text was updated successfully, but these errors were encountered: