Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Skip non-UTF-8 environment entries instead of panicking in config loading (#4563)
Maximilian Roosd187abf90b25
diff --git a/src/config/user/mod.rs b/src/config/user/mod.rsindex 733fe3bf8..ee5c7c39b 100644--- a/src/config/user/mod.rs+++ b/src/config/user/mod.rs@@ -164,7 +164,10 @@ fn parse_worktrunk_env_vars() -> Vec<EnvVar> {"WORKTRUNK_APPROVALS_PATH",];- let mut env_vars: Vec<_> = std::env::vars()+ // `std::env::vars()` panics on any non-UTF-8 entry, including unrelated+ // ones; skip those entries instead.+ let mut env_vars: Vec<_> = std::env::vars_os()+ .filter_map(|(k, v)| Some((k.into_string().ok()?, v.into_string().ok()?))).filter(|(k, _)| k.starts_with("WORKTRUNK_")).filter(|(k, _)| !INFRA_VARS.contains(&k.as_str())).filter(|(k, _)| !k.starts_with("WORKTRUNK_TEST_"))diff --git a/tests/integration_tests/config_show.rs b/tests/integration_tests/config_show.rsindex 4de4d61eb..abadfc139 100644--- a/tests/integration_tests/config_show.rs+++ b/tests/integration_tests/config_show.rs@@ -7970,3 +7970,20 @@ fn test_config_show_reports_failed_migration_diff(repo: TestRepo) {"expected the failure to be reported, got:\n{stdout}");}++/// A non-UTF-8 environment entry must not panic config loading.+#[cfg(unix)]+#[rstest]+fn test_config_show_non_utf8_environment(repo: TestRepo) {+ use std::ffi::OsString;+ use std::os::unix::ffi::OsStringExt;++ let output = repo+ .wt_command()+ .env("UNRELATED", OsString::from_vec(vec![0xff]))+ .env(OsString::from_vec(b"UNRELATED_\xff".to_vec()), "value")+ .args(["config", "show"])+ .output()+ .unwrap();+ assert!(output.status.success(), "{output:?}");+}