Skip to content

ls: enable locale-aware decimal separator for -h/--human-readable - #14326

Open
arbelonson-source wants to merge 1 commit into
uutils:mainfrom
arbelonson-source:fix/ls-human-readable-locale-decimal-separator
Open

ls: enable locale-aware decimal separator for -h/--human-readable#14326
arbelonson-source wants to merge 1 commit into
uutils:mainfrom
arbelonson-source:fix/ls-human-readable-locale-decimal-separator

Conversation

@arbelonson-source

Copy link
Copy Markdown
Contributor

Summary

ls -lh's human-readable size column ignores LC_NUMERIC's decimal separator — it always shows e.g. 4.0K, even under a locale like fr_FR.UTF-8 where GNU ls -lh shows 4,0K. du -h and numfmt --to=iec already handle this correctly in this implementation.

Root cause: uucore::format::human::human_readable() has had locale-aware decimal-separator logic all along, gated behind the i18n-decimal uucore feature flag (localize_decimal, see src/uucore/src/lib/features/format/human.rs). du's and numfmt's Cargo.toml already enable that feature; ls's did not, so it silently compiled against the feature's no-op fallback and always used . regardless of locale.

Fix is a one-line addition of "i18n-decimal" to ls's uucore feature list in src/uu/ls/Cargo.toml, matching du and numfmt.

Fixes #14232

Test plan

  • Added test_human_readable_uses_locale_decimal_separator in tests/by-util/test_ls.rs, asserting ls -lh under LC_ALL=fr_FR.UTF-8 shows 4,0K for a 4000-byte file
  • Verified the new test fails against pre-fix code (reverted the Cargo.toml change locally, confirmed the test fails with 4.0K instead of 4,0K)
  • cargo test --features feat_os_unix --test tests -- test_ls — 187 passed, 1 ignored (WASI-only)
  • cargo clippy -p uu_ls --all-targets -- -D warnings — clean
  • Manually verified against real GNU ls -lh under fr_FR.UTF-8, de_DE.UTF-8, and LC_NUMERIC=C (unaffected) — matches in all three cases

AI-assisted-by: Claude Opus 5, via Claude Code

`ls -lh`'s size column ignored LC_NUMERIC's decimal separator (e.g.
always showing "4.0K" instead of "4,0K" under fr_FR/de_DE locales),
while `du -h` and `numfmt --to=iec` already handled this correctly.

uucore's human_readable() formatter has had locale-aware decimal
separator logic all along, gated behind the "i18n-decimal" uucore
feature flag. du's and numfmt's Cargo.toml already enabled it; ls's
did not, so ls always compiled against the feature's no-op fallback
and silently used '.' regardless of locale.

Fixes uutils#14232

AI-assisted-by: Claude Opus 5, via Claude Code
@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/date/resolution (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/misc/io-errors (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/cut/bounded-memory (passes in this run but fails in the 'main' branch)
Skip an intermittent issue tests/pr/bounded-memory (was skipped on 'main', now failing)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

human readable sizes ignore the locale decimal separator, which breaks du -h | sort -h

1 participant