Skip to content

[parser] Bundled short flags break when a shared meta carries an optional argument (uniq -Dc proven; diff -cu, split -dl same pattern) #1306

Closed

Description

@caomengxuan666

Summary

When a command declares one short option both as a standalone form and fused into a shared long/short meta entry that carries an optional argument, the parser's combined-meta branch wins and the argument-eating semantics change: bundled short flags after it break. Probe-verified on uniq; the same meta pattern exists in diff/split.

Evidence (harness vs GNU, two runs)

  • printf 'dup\ndup\n' | uniq -Dc
    • GNU: uniq: printing all duplicated lines and repeat counts is meaningless + Try, rc1.
    • WinuxCmd: uniq: invalid argument c for --all-repeated, rc1 — the parser fused -Dc into --all-repeated with attached argument c.
  • Pattern sites (code): uniq.cpp declares {"c", "count"} and separately {"", "all-repeated", OptionalString} fused with 'D'. Same shape: diff.cpp (-c context vs -C/--context OptionalInt — probe GNU: diff -cu a b prints unified diff rc1(differs)) and split.cpp (-d vs -l OptionalInt — GNU: split -dl 5 f = numeric suffixes + 5-line chunks).

Source

src/core/opt.cppm: short tokens are matched against combined metas before standalone short defs; an OptionalString/OptionalInt combined meta takes the rest of the bundle as its argument.

Regression seed

  • uniq -Dc probe above → expect GNU's "meaningless" diagnostic.
  • diff -cu a b → unified diff output.
  • split -dl 5 f (f with 12 lines) → splits of 5 lines with numeric suffixes.

Found by the full-audit (argument-form deep audit). uniq probe verified against GNU; diff/split are the same code pattern (verify when fixing).

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