Skip to content

Commit c5bdff1

Browse files
authored
numfmt: treat multibyte chars as a single character (#11992)
* treat multibyte chars as a single character * add test for issue 11937
1 parent 020124b commit c5bdff1

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/uu/numfmt/src/format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ fn transform_to(
620620
/// Right-aligns when `right_align` is true, left-aligns otherwise.
621621
/// Unlike `format!("{:>width$}")`, this handles widths larger than 65535.
622622
fn pad_string(s: &str, width: usize, fill: char, right_align: bool) -> String {
623-
let len = s.len();
623+
let len = s.chars().count();
624624
if len >= width {
625625
return s.to_string();
626626
}

tests/by-util/test_numfmt.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,3 +1549,13 @@ fn test_si_format_precision_no_cap() {
15491549
.succeeds()
15501550
.stdout_is("1.23457M\n");
15511551
}
1552+
1553+
// https://github.com/uutils/coreutils/issues/11937
1554+
// numfmt: --format width accounting diverges from GNU for multi-byte --suffix
1555+
#[test]
1556+
fn test_multibyte_suffix_issue11937() {
1557+
new_ucmd!()
1558+
.args(&["--suffix=€", "--format=%10.2f", "692"])
1559+
.succeeds()
1560+
.stdout_is(" 692.00€\n");
1561+
}

0 commit comments

Comments
 (0)