Skip to content

Fix short flags being consumed as string values#2712

Merged
datduyng merged 1 commit into
mainfrom
domnguyen/fix-short-flag-values
Jul 21, 2026
Merged

Fix short flags being consumed as string values#2712
datduyng merged 1 commit into
mainfrom
domnguyen/fix-short-flag-values

Conversation

@datduyng

@datduyng datduyng commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

A string-valued short flag could incorrectly consume the next short flag as its value. Here, -m expects a match string while -v is a separate boolean flag.

> @const list -m -v

Input:
  -m -> expects a string value
  -v -> verbose boolean flag

Before:
  parsed match -> "-v"
  parsed verbose -> false
  output -> no result

After:
  -v is recognized as another flag, leaving -m without a value
  output -> Missing value for flag '-m'

The short-flag check used an impossible condition (character < "0" && character > "9"). Changing it to || rejects unquoted flag tokens as string values while still allowing negative numeric values such as -1 and quoted values such as '-v'.

pr-2712-before-after.mp4

- Reject unquoted short flags when a value-taking flag is missing its value.

- Preserve negative numeric strings and quoted flag-like values.

- Add focused parser regression coverage.
@datduyng
datduyng marked this pull request as draft July 21, 2026 05:25
@datduyng

Copy link
Copy Markdown
Contributor Author
pr-2712-before-after.mp4

@datduyng
datduyng marked this pull request as ready for review July 21, 2026 20:32
@datduyng
datduyng enabled auto-merge July 21, 2026 20:56
@datduyng
datduyng added this pull request to the merge queue Jul 21, 2026
Merged via the queue into main with commit 59b52ab Jul 21, 2026
27 checks passed
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