1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

shuf: fix error message text on negative-sized ranges

Found by @cakebaker:
https://github.com/uutils/coreutils/pull/6011#discussion_r1501838317
This commit is contained in:
Ben Wiederhake 2024-02-27 23:54:19 +01:00 committed by Sylvestre Ledru
parent 4ee3f68e6a
commit b233569b9c
2 changed files with 11 additions and 3 deletions

View file

@ -471,7 +471,11 @@ fn parse_range(input_range: &str) -> Result<RangeInclusive<usize>, String> {
let end = to
.parse::<usize>()
.map_err(|_| format!("invalid input range: {}", to.quote()))?;
Ok(begin..=end)
if begin <= end || begin == end + 1 {
Ok(begin..=end)
} else {
Err(format!("invalid input range: {}", input_range.quote()))
}
} else {
Err(format!("invalid input range: {}", input_range.quote()))
}

View file

@ -762,7 +762,11 @@ fn test_range_empty() {
#[test]
fn test_range_empty_minus_one() {
new_ucmd!().arg("-i5-3").succeeds().no_output();
new_ucmd!()
.arg("-i5-3")
.fails()
.no_stdout()
.stderr_only("shuf: invalid input range: '5-3'\n");
}
#[test]
@ -792,5 +796,5 @@ fn test_range_repeat_empty_minus_one() {
.arg("-ri5-3")
.fails()
.no_stdout()
.stderr_only("shuf: no lines to repeat\n");
.stderr_only("shuf: invalid input range: '5-3'\n");
}