diff --git a/src/uucore/src/lib/features/format/spec.rs b/src/uucore/src/lib/features/format/spec.rs index 458fbf82b..9bb1fb4ae 100644 --- a/src/uucore/src/lib/features/format/spec.rs +++ b/src/uucore/src/lib/features/format/spec.rs @@ -95,6 +95,7 @@ struct Flags { space: bool, hash: bool, zero: bool, + quote: bool, } impl Flags { @@ -108,6 +109,11 @@ impl Flags { b' ' => flags.space = true, b'#' => flags.hash = true, b'0' => flags.zero = true, + b'\'' => { + // the thousands separator is printed with numbers using the ' flag, but + // this is a no-op in the "C" locale. We only save this flag for reporting errors + flags.quote = true; + } _ => break, } *index += 1; @@ -181,7 +187,7 @@ impl Spec { } } b's' => { - if flags.zero || flags.hash { + if flags.zero || flags.hash || flags.quote { return Err(&start[..index]); } Self::String { diff --git a/tests/by-util/test_printf.rs b/tests/by-util/test_printf.rs index 270fb3746..fb397b08d 100644 --- a/tests/by-util/test_printf.rs +++ b/tests/by-util/test_printf.rs @@ -337,6 +337,16 @@ fn sub_num_int_char_const_in() { .stdout_only("emoji is 128579"); } +#[test] +fn sub_num_thousands() { + // For "C" locale, the thousands separator is ignored but should + // not result in an error + new_ucmd!() + .args(&["%'i", "123456"]) + .succeeds() + .stdout_only("123456"); +} + #[test] fn sub_num_uint() { new_ucmd!()