Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

~ in path resolved into empty string if home_dir is unknown (or unavailable) #106

Closed
micolous opened this issue Dec 18, 2024 · 0 comments
Closed

Comments

@micolous
Copy link
Contributor

Something I noticed while writing #105, but I opted to leave things as they are:

When expanding a ~, if home_dir (or env_home_dir) returns None (eg: $HOME is unset, or on a platform like WASM where there is no home directory), then tilde_expansion() turns it into an empty PathBuf by unwrap_or_default():

which-rs/src/finder.rs

Lines 268 to 276 in 1b5f7be

if o == "~" {
let mut new_path = home_dir().unwrap_or_default();
new_path.extend(component_iter);
#[cfg(feature = "tracing")]
tracing::trace!(
"found tilde, substituting in user's home directory to get {}",
new_path.display()
);
Cow::Owned(new_path)

That would cause which to search a path relative to the current working directory for binaries, rather than the intended path.

This should probably return some error instead (or skip searching paths containing ~ if there is no home directory), but I think that could be a significant behaviour change on some platforms / environments.

Xaeroxe added a commit to Xaeroxe/which-rs that referenced this issue Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant