Skip to content

split: quote a zero SIZE in the invalid-number diagnostic - #14398

Open
Socialpranker wants to merge 1 commit into
uutils:mainfrom
Socialpranker:split-quote-zero-size
Open

split: quote a zero SIZE in the invalid-number diagnostic#14398
Socialpranker wants to merge 1 commit into
uutils:mainfrom
Socialpranker:split-quote-zero-size

Conversation

@Socialpranker

Copy link
Copy Markdown
Contributor

A SIZE that is rejected for being zero was printed bare, while every other
rejected SIZE is quoted:

$ split --lines 0 file        # GNU
split: invalid number of lines: '0'
$ split --lines 0 file        # uutils, before
split: invalid number of lines: 0

$ split --lines 2fb file      # both, already quoted
split: invalid number of lines: '2fb'

Same for --bytes 0, --line-bytes 0 and the obsolete split -0 spelling.

The fix

parse_size_u64_max quotes the value inside the ParseSizeError it
returns, so the parse-failure path was already right. The zero check
happens after that call and built its own ParseSizeError::ParseFailure
from the raw string, unquoted. It now quotes it the same way. Two call
sites: get_and_parse and the obsolete-lines branch.

Three existing assertions in test_split.rs pinned the unquoted form; they
are updated.

How the GNU behavior was established

By running the installed GNU coreutils 9.11 binary (Homebrew, gsplit) as
a black box over -l/-b/-C/-n with the values 0, abc, 1Y,
-200 and an overflowing number, diffing stderr and exit status against
uutils. I did not read GNU coreutils source.

Testing

  • New test_split_zero_size_is_quoted in tests/by-util/test_split.rs
    covers --lines/--bytes/--line-bytes with the exact message and
    exit status 1. Mutation-checked: reverting strategy.rs alone makes it,
    and the two updated tests, fail.
  • cargo test --features split --test tests test_split: 135 passed, 0 failed.
  • cargo clippy -p uu_split --all-targets -- -D warnings: clean.
  • cargo fmt --check: clean.
  • Differential A/B against GNU coreutils 9.11 over the 19 split
    invocations in my harness: mismatches 2 -> 0.

Not in scope

split -C 0 reports "invalid number of bytes" where GNU reports "invalid
number of lines", and the obsolete split -0 spelling omits the
Try 'split --help' line GNU prints. Both are separate from the quoting
and left alone here.

Disclosure

Prepared with AI assistance (Claude Opus 5, via Claude Code), per the AI
policy in CONTRIBUTING.md. Every GNU behavior quoted above came from
running the installed binary, not from reading GPL source. All testing was
run locally.

Every other rejected SIZE is quoted, because parse_size_u64_max quotes the
value it could not parse. A SIZE that parses but is zero took a different
path and printed the value bare:

    $ split --lines 0 file
    split: invalid number of lines: 0     # was
    split: invalid number of lines: '0'   # GNU, and now

Same for --bytes and --line-bytes, and for the obsolete 'split -0' spelling.
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/cut/bounded-memory (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/date/resolution (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/tail/pipe-f 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.

2 participants