Skip to content

Commit 2b211ef

Browse files
authored
Allow reading non-unicode paths (#1223)
* Use `var_os` instead of `var` * One create bin_path and fixed_path when needed
1 parent 8e2d37d commit 2b211ef

3 files changed

Lines changed: 20 additions & 13 deletions

File tree

‎.changeset/var-os.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"fnm": patch
3+
---
4+
5+
Allow reading non-unicode paths from environment variables

‎src/commands/use.rs‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,20 @@ fn warn_if_multishell_path_not_in_path_env_var(
185185
multishell_path: &std::path::Path,
186186
config: &FnmConfig,
187187
) {
188-
let bin_path = if cfg!(unix) {
189-
multishell_path.join("bin")
190-
} else {
191-
multishell_path.to_path_buf()
192-
};
193-
194-
let fixed_path = bin_path.to_str().and_then(shell::maybe_fix_windows_path);
195-
let fixed_path = fixed_path.as_ref().map(|x| &x[..]);
196-
197-
for path in std::env::split_paths(&std::env::var("PATH").unwrap_or_default()) {
198-
if bin_path == path || fixed_path == path.to_str() {
199-
return;
188+
if let Some(path_var) = std::env::var_os("PATH") {
189+
let bin_path = if cfg!(unix) {
190+
multishell_path.join("bin")
191+
} else {
192+
multishell_path.to_path_buf()
193+
};
194+
195+
let fixed_path = bin_path.to_str().and_then(shell::maybe_fix_windows_path);
196+
let fixed_path = fixed_path.as_deref();
197+
198+
for path in std::env::split_paths(&path_var) {
199+
if bin_path == path || fixed_path == path.to_str() {
200+
return;
201+
}
200202
}
201203
}
202204

‎src/directories.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::path_ext::PathExt;
55

66
fn xdg_dir(env: &str) -> Option<PathBuf> {
77
if cfg!(windows) {
8-
let env_var = std::env::var(env).ok()?;
8+
let env_var = std::env::var_os(env)?;
99
Some(PathBuf::from(env_var))
1010
} else {
1111
// On non-Windows platforms, `etcetera` already handles XDG variables

0 commit comments

Comments
 (0)