Skip to content

Commit 1e539da

Browse files
ls: honor LC_NUMERIC for the -h decimal separator
ls -lh (and -h) rendered the fractional size with a period regardless of LC_NUMERIC, so under e.g. fr_FR.UTF-8 it printed "8.4K" where GNU prints "8,4K". ls already formats sizes through uucore's human_readable, which localizes the separator, but the ls crate did not enable the `i18n-decimal` uucore feature, so the localization compiled out. Enable it, matching what du does (see #12357). This makes ls -h agree with sort -h under a comma-decimal locale. Fixes #14232
1 parent 212798d commit 1e539da

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/uu/ls/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ uucore = { workspace = true, features = [
3333
"fsext",
3434
"fsxattr",
3535
"i18n-collator",
36+
"i18n-decimal",
3637
"parser-size",
3738
"parser-glob",
3839
"quoting-style",

tests/by-util/test_ls.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7734,6 +7734,27 @@ fn test_write_error() {
77347734
.stderr_is("ls: write error: No space left on device\n");
77357735
}
77367736

7737+
#[test]
7738+
#[cfg_attr(wasi_runner, ignore = "WASI: locale env vars not propagated")]
7739+
fn test_ls_h_locale_decimal_separator() {
7740+
// `ls -lh` must render the fractional size with the LC_NUMERIC decimal
7741+
// separator, like GNU (and like `du -h`), so `ls -lh | sort -h` agrees.
7742+
for (locale, expected) in [("fr_FR.UTF-8", "8,4K"), ("C", "8.4K")] {
7743+
let (at, mut ucmd) = at_and_ucmd!();
7744+
7745+
let fpath = at.plus("test.txt");
7746+
std::fs::File::create(&fpath)
7747+
.expect("cannot create test file")
7748+
.set_len(8500)
7749+
.expect("cannot truncate test len to size");
7750+
ucmd.env("LC_ALL", locale)
7751+
.arg("-lh")
7752+
.arg(&fpath)
7753+
.succeeds()
7754+
.stdout_contains(expected);
7755+
}
7756+
}
7757+
77377758
#[cfg(all(feature = "feat_diagnostics", not(wasi_runner)))]
77387759
mod diagnostics {
77397760
use super::*;

0 commit comments

Comments
 (0)