Skip to content

Commit

Permalink
Skip empty environment variables on UNIX platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
complexspaces committed Aug 25, 2024
1 parent 836e094 commit d5924c7
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ pub(crate) fn get() -> impl Iterator<Item = String> {
fn _get(env: &impl EnvAccess) -> Option<String> {
let code = env
.get(LC_ALL)
.filter(|val| !val.is_empty())
.or_else(|| env.get(LC_CTYPE))
.filter(|val| !val.is_empty())
.or_else(|| env.get(LANG))?;

parse_locale_code(&code)
Expand Down Expand Up @@ -98,4 +100,17 @@ mod tests {
env.insert(LC_ALL.into(), "invalid-again".to_owned());
assert_eq!(_get(&env).as_deref(), Some("invalid-again"));
}

#[test]
fn env_skips_empty_options() {
let mut env = MockEnv::new();
assert_eq!(_get(&env), None);

env.insert(LC_ALL.into(), String::new());
env.insert(LC_CTYPE.into(), PARSE_LOCALE.to_owned());

let set_code = _get(&env).unwrap();
assert_eq!(set_code, PARSE_LOCALE);
assert_eq!(parse_locale_code(&set_code).as_deref(), Some(PARSE_LOCALE));
}
}

0 comments on commit d5924c7

Please sign in to comment.