diff --git a/.changeset/var-os.md b/.changeset/var-os.md new file mode 100644 index 000000000..8e45762d3 --- /dev/null +++ b/.changeset/var-os.md @@ -0,0 +1,5 @@ +--- +"fnm": patch +--- + +Allow reading non-unicode paths from environment variables diff --git a/src/commands/use.rs b/src/commands/use.rs index 3f2751fb3..3a7f8f2f3 100644 --- a/src/commands/use.rs +++ b/src/commands/use.rs @@ -185,18 +185,20 @@ fn warn_if_multishell_path_not_in_path_env_var( multishell_path: &std::path::Path, config: &FnmConfig, ) { - let bin_path = if cfg!(unix) { - multishell_path.join("bin") - } else { - multishell_path.to_path_buf() - }; - - let fixed_path = bin_path.to_str().and_then(shell::maybe_fix_windows_path); - let fixed_path = fixed_path.as_ref().map(|x| &x[..]); - - for path in std::env::split_paths(&std::env::var("PATH").unwrap_or_default()) { - if bin_path == path || fixed_path == path.to_str() { - return; + if let Some(path_var) = std::env::var_os("PATH") { + let bin_path = if cfg!(unix) { + multishell_path.join("bin") + } else { + multishell_path.to_path_buf() + }; + + let fixed_path = bin_path.to_str().and_then(shell::maybe_fix_windows_path); + let fixed_path = fixed_path.as_deref(); + + for path in std::env::split_paths(&path_var) { + if bin_path == path || fixed_path == path.to_str() { + return; + } } } diff --git a/src/directories.rs b/src/directories.rs index df6d357f2..f09b17b56 100644 --- a/src/directories.rs +++ b/src/directories.rs @@ -5,7 +5,7 @@ use crate::path_ext::PathExt; fn xdg_dir(env: &str) -> Option { if cfg!(windows) { - let env_var = std::env::var(env).ok()?; + let env_var = std::env::var_os(env)?; Some(PathBuf::from(env_var)) } else { // On non-Windows platforms, `etcetera` already handles XDG variables