mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
* Changed dd parsing error message to be in line with GNU dd * Correct logic to make dd incorrect number error message fully compatible with GNU. Add test --------- Co-authored-by: just-an-engineer <Julian.Beltz@zetier.com>
This commit is contained in:
co-authored by
just-an-engineer
parent
e4749381f9
commit
b89a6255a9
@@ -430,7 +430,7 @@ impl std::fmt::Display for ParseError {
|
||||
write!(f, "Unrecognized conv=CONV -> {arg}")
|
||||
}
|
||||
Self::MultiplierStringParseFailure(arg) => {
|
||||
write!(f, "Unrecognized byte multiplier -> {arg}")
|
||||
write!(f, "invalid number: ‘{arg}’")
|
||||
}
|
||||
Self::MultiplierStringOverflow(arg) => {
|
||||
write!(
|
||||
@@ -474,8 +474,9 @@ fn show_zero_multiplier_warning() {
|
||||
}
|
||||
|
||||
/// Parse bytes using str::parse, then map error if needed.
|
||||
fn parse_bytes_only(s: &str) -> Result<u64, ParseError> {
|
||||
s.parse()
|
||||
fn parse_bytes_only(s: &str, i: usize) -> Result<u64, ParseError> {
|
||||
s[..i]
|
||||
.parse()
|
||||
.map_err(|_| ParseError::MultiplierStringParseFailure(s.to_string()))
|
||||
}
|
||||
|
||||
@@ -520,9 +521,9 @@ fn parse_bytes_no_x(full: &str, s: &str) -> Result<u64, ParseError> {
|
||||
return Err(ParseError::InvalidNumber(full.to_string()))
|
||||
}
|
||||
},
|
||||
(Some(i), None, None) => (parse_bytes_only(&s[..i])?, 1),
|
||||
(None, Some(i), None) => (parse_bytes_only(&s[..i])?, 2),
|
||||
(None, None, Some(i)) => (parse_bytes_only(&s[..i])?, 512),
|
||||
(Some(i), None, None) => (parse_bytes_only(s, i)?, 1),
|
||||
(None, Some(i), None) => (parse_bytes_only(s, i)?, 2),
|
||||
(None, None, Some(i)) => (parse_bytes_only(s, i)?, 512),
|
||||
_ => return Err(ParseError::MultiplierStringParseFailure(full.to_string())),
|
||||
};
|
||||
num.checked_mul(multiplier)
|
||||
|
||||
@@ -1775,3 +1775,16 @@ fn test_stdin_stdout_not_rewound_even_when_connected_to_seekable_file() {
|
||||
println!("stdout:\n{}", out_file_content);
|
||||
assert_eq!(out_file_content, "bde");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_wrong_number_err_msg() {
|
||||
new_ucmd!()
|
||||
.args(&["count=kBb"])
|
||||
.fails()
|
||||
.stderr_contains("dd: invalid number: ‘kBb’\n");
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["count=1kBb555"])
|
||||
.fails()
|
||||
.stderr_contains("dd: invalid number: ‘1kBb555’\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user