Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/uucore/src/lib/features/i18n/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const DEFAULT_LOCALE: Locale = locale!("und");
pub fn get_locale_from_env(locale_name: &str) -> (Locale, UEncoding) {
let locale_var = ["LC_ALL", locale_name, "LANG"]
.iter()
.find_map(|&key| std::env::var(key).ok());
.find_map(|&key| std::env::var(key).ok().filter(|v| !v.is_empty()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.find_map(|&key| std::env::var(key).ok().filter(|v| !v.is_empty()));
.find_map(|&key| std::env::var(key).ok())
.filter(|v| !v.is_empty());

this is a bit clearer?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filter needs to stay inside find_map rather than after it — moving it outside would change the semantics:

In that case, we may have incorrect behavior here:

fn is_c_locale() -> bool {
["LC_ALL", "LC_CTYPE", "LANG"]
.iter()
.find_map(|&key| std::env::var_os(key))
.filter(|v| !v.is_empty())
.is_none_or(|v| v == "C" || v == "POSIX")
}


if let Some(locale_var_str) = locale_var {
let mut split = locale_var_str.split(&['.', '@']);
Expand Down
21 changes: 21 additions & 0 deletions tests/by-util/test_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3384,6 +3384,27 @@ mod quoting {
.succeeds()
.stdout_is("é\n");
}

#[test]
fn test_empty_lc_all_falls_through_to_lang() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
// Create a file with a non-ASCII character.
at.touch("café");

// When LC_ALL is empty it should be treated as unset,
// falling through to LANG for locale resolution.
// Without the fix, empty LC_ALL was treated as POSIX,
// causing the non-ASCII name to be octal-escaped.
scene
.ucmd()
.env("LC_ALL", "")
.env("LANG", "en_US.UTF-8")
.env("LC_CTYPE", "en_US.UTF-8")
.args(&["--quoting-style=literal"])
.succeeds()
.stdout_contains("café");
}
}

#[test]
Expand Down
Loading