Skip to content

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

Open
Socialpranker wants to merge 2 commits into
uutils:mainfrom
Socialpranker:split-quote-zero-size
Open

Socialpranker wants to merge 2 commits 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.

@github-actions

github-actions Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/tail/tail-n0f (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/tail/retry (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/rm/many-dir-entries-vs-OOM is now being skipped but was previously passing.

Comment on lines +1708 to +1725
#[test]
fn test_split_zero_size_is_quoted() {
let scene = TestScenario::new(util_name!());
scene.fixtures.touch("file");

for (option, message) in [
("--lines", "invalid number of lines"),
("--bytes", "invalid number of bytes"),
("--line-bytes", "invalid number of bytes"),
] {
scene
.ucmd()
.args(&[option, "0", "file"])
.fails_with_code(1)
.no_stdout()
.stderr_contains(format!("split: {message}: '0'\n"));
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is more or less a duplicate of test_split_invalid_input but with long options. So I would combine them.

@Socialpranker

Copy link
Copy Markdown
Contributor Author

merged it into test_split_invalid_input, long options are just extra cases in the same test now

} else {
Err(StrategyError::Lines(
ParseSizeError::ParseFailure(v.to_string()),
ParseSizeError::ParseFailure(v.to_string().quote().to_string()),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v is the parsed number here, so split -00 prints '0' and not '00'. Could we quote the raw input instead of v.to_string().quote().to_string()?

0630039863abc-ui and others added 2 commits December 1, 2026 10:01
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.
@sylvestre
sylvestre force-pushed the split-quote-zero-size branch from d5f0be3 to d2bd4f1 Compare December 1, 2026 09:01

This branch has not been deployed

No deployments
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.

4 participants