Skip to content

Commit 428b2fc

Browse files
committed
fix(wc): keep WASI default locale UTF-8 compatible
WASI does not provide an ambient locale, so treating a missing LC_CTYPE/LANG as C/POSIX makes wc -m count bytes by default. Preserve the existing UTF-8 behavior for WASI while keeping POSIX fallback on platforms with native locale environments.
1 parent 5402711 commit 428b2fc

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/uucore/src/lib/features/i18n/charmap.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ fn get_effective_ctype_locale() -> Option<String> {
4141

4242
/// Return whether the effective `LC_CTYPE` locale is the byte-oriented C/POSIX locale.
4343
///
44-
/// A missing effective locale defaults to POSIX behavior. Only exact `C` and
45-
/// `POSIX` locale values are treated as explicit C/POSIX locales; locales such
46-
/// as `C.UTF-8` are not.
44+
/// A missing effective locale defaults to POSIX behavior on platforms with a
45+
/// native locale environment. WASI has no ambient locale, so its default stays
46+
/// UTF-8-compatible.
4747
pub fn is_effective_ctype_c_or_posix() -> bool {
48-
get_effective_ctype_locale().is_none_or(|locale| locale == "C" || locale == "POSIX")
48+
match get_effective_ctype_locale().as_deref() {
49+
Some("C" | "POSIX") => true,
50+
Some(_) => false,
51+
None => cfg!(not(target_os = "wasi")),
52+
}
4953
}
5054

5155
fn get_encoding() -> &'static MbEncoding {

0 commit comments

Comments
 (0)