mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
cut: fail when the input == usize::MAX
This commit is contained in:
parent
4038907de6
commit
99120d32c1
2 changed files with 10 additions and 0 deletions
|
@ -38,6 +38,8 @@ impl FromStr for Range {
|
||||||
fn parse(s: &str) -> Result<usize, &'static str> {
|
fn parse(s: &str) -> Result<usize, &'static str> {
|
||||||
match s.parse::<usize>() {
|
match s.parse::<usize>() {
|
||||||
Ok(0) => Err("fields and positions are numbered from 1"),
|
Ok(0) => Err("fields and positions are numbered from 1"),
|
||||||
|
// GNU fails when we are at the limit. Match their behavior
|
||||||
|
Ok(n) if n == usize::MAX => Err("byte/character offset is too large"),
|
||||||
Ok(n) => Ok(n),
|
Ok(n) => Ok(n),
|
||||||
Err(_) => Err("failed to parse range"),
|
Err(_) => Err("failed to parse range"),
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,6 +117,14 @@ fn test_whitespace_with_char() {
|
||||||
.code_is(1);
|
.code_is(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_too_large() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-b1-18446744073709551615", "/dev/null"])
|
||||||
|
.fails()
|
||||||
|
.code_is(1);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_specify_delimiter() {
|
fn test_specify_delimiter() {
|
||||||
for param in ["-d", "--delimiter", "--del"] {
|
for param in ["-d", "--delimiter", "--del"] {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue