Skip to content

Commit

Permalink
shuf: fix error message text on negative-sized ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
BenWiederhake committed Feb 27, 2024
1 parent c1cf583 commit 5fe4ed1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/uu/shuf/src/shuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
Expand Down
8 changes: 6 additions & 2 deletions tests/by-util/test_shuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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");
}

0 comments on commit 5fe4ed1

Please sign in to comment.