Repository navigation
nl, basename, paste: accept a value that begins with a hyphen - #14256
Open
arbelonson-source wants to merge 1 commit into
Open
arbelonson-source wants to merge 1 commit into
arbelonson-source wants to merge 1 commit into
Conversation
|
Binary size comparison: |
|
GNU testsuite comparison: |
arbelonson-source
force-pushed
the
fix/hyphen-leading-option-values
branch
2 times, most recently
from
August 30, 2026 21:46
fbbfac4 to
1755d22
Compare
GNU passes the argument after an option to that option even when it
starts with a hyphen. Three options rejected it outright instead, so
input GNU handles fine was refused:
$ nl -v -1 f # GNU numbers from -1
error: unexpected argument '-1' found
$ basename -s -1 /a/b-1 # GNU prints b
error: unexpected argument '-1' found
$ paste -d -1 f1 f2 # GNU uses "-1" as the delimiter list
error: unexpected argument '-1' found
`nl -v` already parses into an i64 and its attached spellings (`-v-10`,
`--starting-line-number=-10`) already worked, so only the separated form
was affected; it gets `allow_negative_numbers`, since only a number is
ever valid there. The suffix and delimiter list are arbitrary strings,
so those get `allow_hyphen_values`.
arbelonson-source
force-pushed
the
fix/hyphen-leading-option-values
branch
from
September 3, 2026 14:00
1755d22 to
417c406
Compare
sylvestre
reviewed
Nov 14, 2026
| .value_name("LIST") | ||
| // A delimiter list may begin with a hyphen: GNU reads `-d -1` | ||
| // as the list "-1" rather than rejecting it as an option. | ||
| .allow_hyphen_values(true) |
Contributor
There was a problem hiding this comment.
allow_hyphen_values(true) is already set 3 lines below, so this is a no-op. please drop it (and the paste part of the PR)
| #[test] | ||
| fn test_delimiter_beginning_with_hyphen() { | ||
| // A delimiter list may start with a hyphen; GNU reads `-d -1` as "-1". | ||
| new_ucmd!() |
Contributor
There was a problem hiding this comment.
with a single input the delimiter is never used, so this passes on main too. could you please use two inputs so -1 actually shows up in the output?
This branch has not been deployed
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.
GNU passes the argument after an option to that option even when it begins with a hyphen. Three options rejected it outright instead, so input GNU handles fine was refused.
nl -v -1 f-1error: unexpected argument '-1' foundbasename -s -1 /a/b-1berror: unexpected argument '-1' foundpaste -d -1 f1 f2-1as the delimiter listerror: unexpected argument '-1' foundFound by differential testing against GNU coreutils 9.11. These are refusals rather than wrong output — the commands simply do not run.
nl -valready parses into ani64, and its attached spellings (-v-10,--starting-line-number=-10) already worked and are already covered bytest_negative_starting_line_number. Only the separated form was affected, so it getsallow_negative_numbers— a number is the only thing ever valid there. A suffix and a delimiter list are arbitrary strings, so those getallow_hyphen_values.Testing
One regression test per utility. Verified they catch the bugs by reverting the three source files alone — all three fail, then pass with them restored.
cargo test --features "nl,basename,paste" --no-default-features: 119 passed, 0 failed (116 pre-existing, 3 new)cargo fmt --checkandcargo clippy -p uu_nl -p uu_basename -p uu_paste --all-targets: cleannl -v 3,basename -s .txt,paste -d ,,paste -d -, barepaste) as regression cover: 10 of 11 match GNUThe one that still differs
nl -v -- -1— GNU takes--itself as the value and reportsinvalid starting line number: '--', while uutils says a value is required. I checked this against an unmodified tree before writing the tests: it behaves identically there, so it is pre-existing and not something this change introduces. It is about how--is treated as an option value, which is a separate matter from accepting hyphen-leading ones.Disclosure
Prepared with AI assistance (Claude Opus 5, via Claude Code), per the AI policy in CONTRIBUTING.md. On the GPL point raised there: expected behavior was established by running the installed GNU binaries as a black box and recording their output. I did not read GNU coreutils source. All testing above was run locally.