Skip to content

Commit

Permalink
Allow reading non-unicode paths (#1223)
Browse files Browse the repository at this point in the history
* Use `var_os` instead of `var`

* One create bin_path and fixed_path when needed
  • Loading branch information
mo8it authored Aug 13, 2024
1 parent 8e2d37d commit 2b211ef
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/var-os.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fnm": patch
---

Allow reading non-unicode paths from environment variables
26 changes: 14 additions & 12 deletions src/commands/use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/directories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::path_ext::PathExt;

fn xdg_dir(env: &str) -> Option<PathBuf> {
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
Expand Down

0 comments on commit 2b211ef

Please sign in to comment.