diff --git a/src/uu/split/src/strategy.rs b/src/uu/split/src/strategy.rs index 0388cb5de1..fe7af75878 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 18a5978a2a..39222e8f96 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"])