Skip to content

[parser] Int long option with empty = value (--opt=) consumes the next argv #1302

Closed

Description

@caomengxuan666

Summary

For Int long options, an empty inline value (--opt=) is not distinguished from "no = at all": the parser falls through and consumes the next argv as the value. The shared parser's own String branch handles this correctly via has_inline_value; the Int branch only checks value.empty().

Evidence (harness vs GNU, two runs)

  • grep --max-count= -e x f
    • GNU: grep: invalid max count, exit 2 (rejects the empty value itself).
    • WinuxCmd: grep: invalid argument '-e' for '--max-count' — the error names -e, proving -e was consumed as the max-count value.
  • Scope note (probe-tested counter-evidence): head --lines= 5 f behaves correctly in WinuxCmd (head: invalid number of lines: '', rc1, identical to GNU) — head is shielded by its dispatcher rewrite hook. The defect is in the shared Int path and surfaces on commands that use it directly (grep proven).

Source

src/core/opt.cppm Int branch (~L266-291): if (!value.empty()) uses the inline value, otherwise consumes the next argv; empty inline value is indistinguishable from absent. String branch (~L293-306) uses has_inline_value correctly. Single-dash-long Int has the same shape (~L380-400).

Regression seed

  • grep --max-count= -e x f → expect grep: invalid max count rc2 (and specifically an error about the empty value, not about -e).

Found by the full-audit (argument-form deep audit).

Activity

  1. added
    bug
    compat-gap
    on Oct 26, 2026
  2. added a commit that references this issue on Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugcompat-gap

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions