Skip to content

fix: improve CLI number validation and add regression tests#20697

Merged
alexander-akait merged 3 commits intowebpack:mainfrom
phoekerson:main
Mar 25, 2026
Merged

fix: improve CLI number validation and add regression tests#20697
alexander-akait merged 3 commits intowebpack:mainfrom
phoekerson:main

Conversation

@phoekerson
Copy link
Copy Markdown
Contributor

@phoekerson phoekerson commented Mar 24, 2026

Ensure numeric inputs are strictly validated against DECIMAL_NUMBER_REGEXP before conversion. Added tests to reject Infinity and hex values in watch options to prevent ambiguous parsing.

Summary

This PR fixes CLI number parsing by strictly validating numeric string inputs with DECIMAL_NUMBER_REGEXP before converting them with Number(...).
It also adds regression tests to ensure ambiguous numeric formats like Infinity and hex values (e.g. 0x10) are rejected for watch options.

What kind of change does this PR introduce?

Bug fix (CLI argument validation improvement) + test coverage improvements.

Did you add tests for your changes?

Yes.
Added/updated tests in test/Cli.basictest.js:

valid decimal/scientific numeric string cases
invalid numeric edge cases
explicit rejection of Infinity and hex-style values in watch options

Does this PR introduce a breaking change?

No.
This change only tightens validation for invalid/ambiguous numeric CLI inputs and does not change valid input behavior.

If relevant, what needs to be documented once your changes are merged or what have you already documented?
No additional documentation is required.
CLI behavior for valid numeric inputs remains the same; invalid ambiguous formats are now consistently rejected.

Use of AI

Ensure numeric inputs are strictly validated against DECIMAL_NUMBER_REGEXP
before conversion. Added tests to reject Infinity and hex values in
watch options to prevent ambiguous parsing.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 24, 2026

⚠️ No Changeset found

Latest commit: bb711ae

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Mar 24, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

Comment thread lib/cli.js

/** @typedef {null | string | number | boolean | RegExp | EnumValue | []} ParsedValue */

const DECIMAL_NUMBER_REGEXP = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a lot of untested chages around e and around (?:\d+\.?\d*|\.\d+) group

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests for decimal forms (leading dot, trailing dot, explicit +) and scientific notation (e / E, optional +/- on exponent). Added negative cases for incomplete/invalid exponent and malformed decimals so the regexp behavior is fully covered.

Copy link
Copy Markdown
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need more tests

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Mar 24, 2026

Merging this PR will degrade performance by 20.29%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 2 improved benchmarks
❌ 1 regressed benchmark
✅ 141 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory benchmark "many-modules-esm", scenario '{"name":"mode-production","mode":"production"}' 7.6 MB 9.5 MB -20.29%
Memory benchmark "future-defaults", scenario '{"name":"mode-production","mode":"production"}' 9.6 MB 8 MB +21.16%
Memory benchmark "lodash", scenario '{"name":"mode-development","mode":"development"}' 5.3 MB 4.1 MB +29.59%

Comparing phoekerson:main (bb711ae) with main (72598ef)

Open in CodSpeed

@alexander-akait alexander-akait merged commit 7bde8ab into webpack:main Mar 25, 2026
55 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

This PR is packaged and the instant preview is available (7bde8ab).

Install it locally:

  • npm
npm i -D webpack@https://pkg.pr.new/webpack@7bde8ab
  • yarn
yarn add -D webpack@https://pkg.pr.new/webpack@7bde8ab
  • pnpm
pnpm add -D webpack@https://pkg.pr.new/webpack@7bde8ab

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants