Skip to content

fix: accept hex digit f/F in int, bigint and float CLI argument types - #8527

Open
pucedoteth wants to merge 1 commit into
NomicFoundation:v2from
pucedoteth:fix/hex-f-cli-argument-types
Open

fix: accept hex digit f/F in int, bigint and float CLI argument types#8527
pucedoteth wants to merge 1 commit into
NomicFoundation:v2from
pucedoteth:fix/hex-f-cli-argument-types

Conversation

@pucedoteth

Copy link
Copy Markdown
Contributor

Problem

The int, bigint and float CLI argument types each validate hex input with the same pattern in packages/hardhat-core/src/internal/core/params/argumentTypes.ts:

const hexPattern = /^0[xX][\dABCDEabcde]+$/;

The character class spells out ABCDE and abcde — every hex digit except f/F.

So any hex argument containing an f is rejected as invalid:

value accepted today
0xa, 0x0a, 0xABCDE
0xF, 0xf
0xff
0xdeadbeef
0xABCDEF

f shows up in about half of all multi-digit hex values, so this rejects a large share of legitimate input — a task taking --value 0xff fails with Invalid value for argument.

It reads like a hand-enumerated class where the last digit was simply missed.

Fix

const hexPattern = /^0[xX][\dA-Fa-f]+$/;

Applied at all three call sites (int, bigint, float).

Worth noting this matches what Hardhat 3 already does — packages/hardhat/src/internal/core/arguments.ts on main defines VALID_HEX_PATTERN = /^0[xX][\dA-Fa-f]+$/. The rewrite got it right; this brings v2 in line.

Tests

Extended the existing argumentTypes suite 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 v2 today; the negative cases and the existing 0xa / 0x0a / x123 assertions are unchanged.

Note

I originally raised this against the wrong base by mistake. This is the same fix rebuilt cleanly on the current v2 head — packages/hardhat-core only exists on this branch, and the bug is still present in all three places there.

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-bot

changeset-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9aa364f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
hardhat Patch

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants