fix: preserve 0x prefix when coercing hex string with byteAligned#3126
Open
JSap0914 wants to merge 1 commit into
Open
fix: preserve 0x prefix when coercing hex string with byteAligned#3126JSap0914 wants to merge 1 commit into
JSap0914 wants to merge 1 commit into
Conversation
When string.hex({ byteAligned: true }) is used with prefix: 'optional'
or prefix: true, the coerce phase incorrectly prepended '0' before the
entire value including the '0x'/'0X' prefix (e.g. '0xABC' → '00xABC'),
producing an invalid hex string that then failed the hex regex check.
The fix inserts the padding zero after the two-character prefix so that
'0xABC' is correctly coerced to '0x0ABC' and '0XABC' to '0X0ABC'.
Values without a prefix are unaffected.
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.
Bug
string.hex({ byteAligned: true })combined withprefix: 'optional'orprefix: trueincorrectly coerces odd-length hex strings. The coerce phase prepends'0'before the entire value — including the0x/0Xprefix — producing an invalid hex string that then fails thestring.hexregex check:Fix
When the value starts with a
0x/0Xprefix, insert the padding zero after the two-character prefix instead of before the whole string. Values without a prefix are unaffected.Files changed:
lib/types/string.js(1 line → 5 lines),test/types/string.js(18 lines added)Verification