diff --git a/src/uu/numfmt/src/format.rs b/src/uu/numfmt/src/format.rs index 6f0a6cbf389..7c4ad723be8 100644 --- a/src/uu/numfmt/src/format.rs +++ b/src/uu/numfmt/src/format.rs @@ -130,6 +130,12 @@ fn remove_suffix(i: f64, s: Option, u: &Unit) -> Result { "missing 'i' suffix in input: '{}{:?}' (e.g Ki/Mi/Gi)", i, raw_suffix )), + (Some((raw_suffix, with_i)), &Unit::None) => Err(format!( + "rejecting suffix in input: '{}{:?}{}' (consider using --from)", + i, + raw_suffix, + if with_i { "i" } else { "" } + )), (None, _) => Ok(i), (_, _) => Err("This suffix is unsupported for specified unit".to_owned()), } diff --git a/tests/by-util/test_numfmt.rs b/tests/by-util/test_numfmt.rs index dce2b094192..be46d7891aa 100644 --- a/tests/by-util/test_numfmt.rs +++ b/tests/by-util/test_numfmt.rs @@ -646,3 +646,19 @@ fn test_invalid_unit_size() { } } } + +#[test] +fn test_valid_but_forbidden_suffix() { + let numbers = vec!["12K", "12Ki"]; + + for number in numbers { + new_ucmd!() + .arg(number) + .fails() + .code_is(2) + .stderr_contains(format!( + "rejecting suffix in input: '{}' (consider using --from)", + number + )); + } +}