Skip to content

expand, unexpand: read a hyphen-leading tab list as a tab list - #14291

Open
arbelonson-source wants to merge 1 commit into
uutils:mainfrom
arbelonson-source:fix/expand-unexpand-tab-list-hyphen
Open

expand, unexpand: read a hyphen-leading tab list as a tab list#14291
arbelonson-source wants to merge 1 commit into
uutils:mainfrom
arbelonson-source:fix/expand-unexpand-tab-list-hyphen

Conversation

@arbelonson-source

Copy link
Copy Markdown
Contributor

-1 is the obsolete spelling of --tabs=1, and expand_shortcuts rewrote it wherever it appeared — including where it was already the value of -t.

Command GNU uutils before
expand -t -1 f tab size contains invalid character(s): '-1' error: a value is required for '--tabs <N, LIST>' but none was supplied
expand -t -0 f tab size contains invalid character(s): '-0' same clap error
unexpand -t -1 f tab size contains invalid character(s): '-1' same clap error

The check that produces GNU's message is already here and already correct — expand -t abc and expand -t 1,-2 match GNU byte for byte today. The hyphen-leading value simply never reached it: clap took -1 for an option, and when allowed through, expand_shortcuts rewrote it to --tabs=1 so the message named the rewritten token rather than what was typed.

Found by differential testing against GNU coreutils 9.11.

Approach

The obsolete -N form is now rewritten only where an option is expected — not as the value of -t/--tabs, and not after a -- terminator, which GNU treats as a file name. allow_hyphen_values lets clap pass the value through to the existing check.

Same shape as the --/option-value handling in #14248 and #14255.

Testing

  • 26-case differential check against GNU across both utilities: all match, including the forms that had to keep working — the obsolete -4 and -1,3, the attached -t8, --tabs=4, clusters (-it 4, -at 4), and -- -1
  • One regression test per utility, covering -t -1 and -t -0 plus the obsolete spelling still working
  • cargo test --features "expand,unexpand" --no-default-features: 93 passed, 0 failed (91 pre-existing, 2 new)
  • cargo fmt --check and cargo clippy -p uu_expand -p uu_unexpand --all-targets: clean

Disclosure

Prepared with AI assistance (Claude Opus 5, via Claude Code), per the AI policy in CONTRIBUTING.md. The GNU behaviour above was established by running the installed GNU binaries as a black box; I did not read GNU coreutils source. All testing was run locally.

`-1` is the obsolete spelling of `--tabs=1`, and `expand_shortcuts`
rewrote it wherever it appeared, including where it was already the
value of `-t`:

    $ expand -t -1 file
    error: a value is required for '--tabs <N, LIST>' but none was supplied

GNU reads it as a (bad) tab list and reports it as one:
`tab size contains invalid character(s): '-1'`. The check that produces
that message already exists here -- `expand -t abc` and `expand -t 1,-2`
match GNU today -- the value just never reached it.

Rewrite the obsolete form only where an option is expected: not as the
value of -t/--tabs, and not past a `--` terminator, which GNU treats as
a file name. `allow_hyphen_values` lets clap pass the value through.
@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/tail/tail-n0f is now passing!

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.

1 participant