expand, unexpand: read a hyphen-leading tab list as a tab list - #14291
Open
arbelonson-source wants to merge 1 commit into
Open
expand, unexpand: read a hyphen-leading tab list as a tab list#14291arbelonson-source wants to merge 1 commit into
arbelonson-source wants to merge 1 commit into
Conversation
`-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.
|
GNU testsuite comparison: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
-1is the obsolete spelling of--tabs=1, andexpand_shortcutsrewrote it wherever it appeared — including where it was already the value of-t.expand -t -1 ftab size contains invalid character(s): '-1'error: a value is required for '--tabs <N, LIST>' but none was suppliedexpand -t -0 ftab size contains invalid character(s): '-0'unexpand -t -1 ftab size contains invalid character(s): '-1'The check that produces GNU's message is already here and already correct —
expand -t abcandexpand -t 1,-2match GNU byte for byte today. The hyphen-leading value simply never reached it: clap took-1for an option, and when allowed through,expand_shortcutsrewrote it to--tabs=1so the message named the rewritten token rather than what was typed.Found by differential testing against GNU coreutils 9.11.
Approach
The obsolete
-Nform 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_valueslets clap pass the value through to the existing check.Same shape as the
--/option-value handling in #14248 and #14255.Testing
-4and-1,3, the attached-t8,--tabs=4, clusters (-it 4,-at 4), and-- -1-t -1and-t -0plus the obsolete spelling still workingcargo test --features "expand,unexpand" --no-default-features: 93 passed, 0 failed (91 pre-existing, 2 new)cargo fmt --checkandcargo clippy -p uu_expand -p uu_unexpand --all-targets: cleanDisclosure
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.