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

Tilde expand windows paths with backward slashes #16

Open
mjptree opened this issue Jan 28, 2022 · 2 comments
Open

Tilde expand windows paths with backward slashes #16

mjptree opened this issue Jan 28, 2022 · 2 comments

Comments

@mjptree
Copy link

mjptree commented Jan 28, 2022

The following tilde expansion check is insufficient on windows if the input path uses backslash notation:

shellexpand/src/lib.rs

Lines 665 to 690 in e707d07

pub fn tilde_with_context<SI: ?Sized, P, HD>(input: &SI, home_dir: HD) -> Cow<str>
where
SI: AsRef<str>,
P: AsRef<Path>,
HD: FnOnce() -> Option<P>,
{
let input_str = input.as_ref();
if input_str.starts_with("~") {
let input_after_tilde = &input_str[1..];
if input_after_tilde.is_empty() || input_after_tilde.starts_with("/") {
if let Some(hd) = home_dir() {
let result = format!("{}{}", hd.as_ref().display(), input_after_tilde);
result.into()
} else {
// home dir is not available
input_str.into()
}
} else {
// we cannot handle `~otheruser/` paths yet
input_str.into()
}
} else {
// input doesn't start with tilde
input_str.into()
}
}

Specifically the test:

        if input_after_tilde.is_empty() || input_after_tilde.starts_with("/") {

The path "~/.cargo" e.g. would expand correctly, however "~\\.cargo" would fail to expand correctly.

@ijackson
Copy link

ijackson commented Aug 3, 2022

Hi. As discussed in #17 I am taking over maintenance of this crate. The new repository is here: https://gitlab.com/ijackson/rust-shellexpand

I think I agree with this bug report. I have reproduced it here https://gitlab.com/ijackson/rust-shellexpand/-/issues/4 in the new repo. I'm afraid I don't have time to fix it right now but I would welcome an MR.

@Trolldemorted
Copy link

Hi. As discussed in #17 I am taking over maintenance of this crate. The new repository is here: https://gitlab.com/ijackson/rust-shellexpand

this should really go into the readme

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

3 participants