From be1e3e5caef6b62f136c8add3ef2c6092959466c Mon Sep 17 00:00:00 2001 From: Socialpranker <0630039863abc@gmail.com> Date: Sat, 5 Sep 2026 19:22:05 +0200 Subject: [PATCH] split: quote a zero SIZE in the invalid-number diagnostic 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. --- src/uu/split/src/strategy.rs | 7 +++++-- tests/by-util/test_split.rs | 30 +++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/uu/split/src/strategy.rs b/src/uu/split/src/strategy.rs index 0388cb5de1b..fe7af75878f 100644 --- a/src/uu/split/src/strategy.rs +++ b/src/uu/split/src/strategy.rs @@ -266,7 +266,10 @@ impl Strategy { if n > 0 { Ok(strategy(n)) } else { - Err(error(ParseSizeError::ParseFailure(s.to_owned()), origin())) + Err(error( + ParseSizeError::ParseFailure(s.quote().to_string()), + origin(), + )) } } // Check that the user is not specifying more than one strategy. @@ -288,7 +291,7 @@ impl Strategy { Ok(Self::Lines(v)) } else { Err(StrategyError::Lines( - ParseSizeError::ParseFailure(v.to_string()), + ParseSizeError::ParseFailure(v.to_string().quote().to_string()), None, )) } diff --git a/tests/by-util/test_split.rs b/tests/by-util/test_split.rs index 18a5978a2ab..39222e8f96a 100644 --- a/tests/by-util/test_split.rs +++ b/tests/by-util/test_split.rs @@ -428,12 +428,12 @@ fn test_split_lines_number() { .ucmd() .args(&["--lines", "0", "file"]) .fails_with_code(1) - .stderr_only("split: invalid number of lines: 0\n"); + .stderr_only("split: invalid number of lines: '0'\n"); scene .ucmd() .args(&["-0", "file"]) .fails_with_code(1) - .stderr_only("split: invalid number of lines: 0\n"); + .stderr_only("split: invalid number of lines: '0'\n"); scene .ucmd() .args(&["--lines", "2fb", "file"]) @@ -1704,6 +1704,26 @@ fn test_round_robin_limited_file_descriptors() { .succeeds(); } +/// A zero SIZE is quoted like any other rejected SIZE, as GNU does. +#[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")); + } +} + #[test] fn test_split_invalid_input() { // Test if stdout/stderr for '--lines' option is correct @@ -1716,19 +1736,19 @@ fn test_split_invalid_input() { .args(&["--lines", "0", "file"]) .fails() .no_stdout() - .stderr_contains("split: invalid number of lines: 0"); + .stderr_contains("split: invalid number of lines: '0'"); scene .ucmd() .args(&["-C", "0", "file"]) .fails() .no_stdout() - .stderr_contains("split: invalid number of bytes: 0"); + .stderr_contains("split: invalid number of bytes: '0'"); scene .ucmd() .args(&["-b", "0", "file"]) .fails() .no_stdout() - .stderr_contains("split: invalid number of bytes: 0"); + .stderr_contains("split: invalid number of bytes: '0'"); scene .ucmd() .args(&["-n", "0", "file"])