diff --git a/src/uucore/src/lib/features/format/spec.rs b/src/uucore/src/lib/features/format/spec.rs index 7c0d02367..8eaf66087 100644 --- a/src/uucore/src/lib/features/format/spec.rs +++ b/src/uucore/src/lib/features/format/spec.rs @@ -115,12 +115,6 @@ impl Spec { index += 1; } - let alignment = match (minus, zero) { - (true, _) => NumberAlignment::Left, - (false, true) => NumberAlignment::RightZero, - (false, false) => NumberAlignment::RightSpace, - }; - let positive_sign = match (plus, space) { (true, _) => PositiveSign::Plus, (false, true) => PositiveSign::Space, @@ -136,6 +130,17 @@ impl Spec { None }; + // The `0` flag is ignored if `-` is given or a precision is specified. + // So the only case for RightZero, is when `-` is not given and the + // precision is none. + let alignment = if minus { + NumberAlignment::Left + } else if zero && precision.is_none() { + NumberAlignment::RightZero + } else { + NumberAlignment::RightSpace + }; + // We ignore the length. It's not really relevant to printf let _ = Self::parse_length(rest, &mut index); diff --git a/tests/by-util/test_csplit.rs b/tests/by-util/test_csplit.rs index d4b521660..df1034436 100644 --- a/tests/by-util/test_csplit.rs +++ b/tests/by-util/test_csplit.rs @@ -1357,3 +1357,18 @@ fn precision_format() { assert_eq!(at.read("xx 000"), generate(1, 10)); assert_eq!(at.read("xx 0x001"), generate(10, 51)); } + +#[test] +fn precision_format2() { + let (at, mut ucmd) = at_and_ucmd!(); + ucmd.args(&["numbers50.txt", "10", "--suffix-format", "%0#6.3x"]) + .succeeds() + .stdout_only("18\n123\n"); + + let count = glob(&at.plus_as_string("xx*")) + .expect("there should be splits created") + .count(); + assert_eq!(count, 2); + assert_eq!(at.read("xx 000"), generate(1, 10)); + assert_eq!(at.read("xx 0x001"), generate(10, 51)); +}