From d5924c75731aae0ef2f51730ab0af852fdf9a56d Mon Sep 17 00:00:00 2001 From: ComplexSpaces Date: Sun, 25 Aug 2024 14:31:01 -0500 Subject: [PATCH] Skip empty environment variables on UNIX platforms --- src/unix.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/unix.rs b/src/unix.rs index cc3fbd4..bef6d92 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -29,7 +29,9 @@ pub(crate) fn get() -> impl Iterator { fn _get(env: &impl EnvAccess) -> Option { 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) @@ -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)); + } }