fix: accept hex digit f/F in int, bigint and float CLI argument types - #8527
Open
pucedoteth wants to merge 1 commit into
Open
fix: accept hex digit f/F in int, bigint and float CLI argument types#8527pucedoteth wants to merge 1 commit into
pucedoteth wants to merge 1 commit into
Conversation
The hex pattern shared by the `int`, `bigint` and `float` CLI argument types is `/^0[xX][\dABCDEabcde]+$/`. The character class runs A-E and a-e, so it matches every hex digit except `f`/`F`. Any hex argument containing an `f` is therefore rejected as invalid: `0xff`, `0xdeadbeef` and `0xF` all fail, while `0xa` and `0xABCDE` are accepted. Since `f` appears in roughly half of all multi-digit hex values, this rejects a large share of legitimate input. Widen the class to `[\dA-Fa-f]`. Invalid input is still rejected — `0xg` and `x123` continue to fail.
🦋 Changeset detectedLatest commit: 9aa364f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
1 task
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.
Problem
The
int,bigintandfloatCLI argument types each validate hex input with the same pattern inpackages/hardhat-core/src/internal/core/params/argumentTypes.ts:The character class spells out
ABCDEandabcde— every hex digit exceptf/F.So any hex argument containing an
fis rejected as invalid:0xa,0x0a,0xABCDE0xF,0xf0xff0xdeadbeef0xABCDEFfshows up in about half of all multi-digit hex values, so this rejects a large share of legitimate input — a task taking--value 0xfffails withInvalid value for argument.It reads like a hand-enumerated class where the last digit was simply missed.
Fix
Applied at all three call sites (
int,bigint,float).Worth noting this matches what Hardhat 3 already does —
packages/hardhat/src/internal/core/arguments.tsonmaindefinesVALID_HEX_PATTERN = /^0[xX][\dA-Fa-f]+$/. The rewrite got it right; this brings v2 in line.Tests
Extended the existing
argumentTypessuite rather than adding a new one — five positive cases per type (0xF,0xf,0xff,0xdeadbeef,0xABCDEF) and one negative (0xg) to pin down that widening the class doesn't start accepting non-hex.Every one of the positive cases fails on
v2today; the negative cases and the existing0xa/0x0a/x123assertions are unchanged.Note
I originally raised this against the wrong base by mistake. This is the same fix rebuilt cleanly on the current
v2head —packages/hardhat-coreonly exists on this branch, and the bug is still present in all three places there.