Skip to content

Commit

Permalink
When searching for ./script.sh, don't return /path/to/./script.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobhellermann authored and Xaeroxe committed Feb 6, 2025
1 parent 68acf2c commit 87acc08
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ impl PathExt for PathBuf {
self
} else {
let mut new_path = PathBuf::from(cwd.as_ref());
new_path.push(self);
new_path.extend(
self.components()
.skip_while(|c| matches!(c, Component::CurDir)),
);
new_path
}
}
Expand Down
18 changes: 18 additions & 0 deletions tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ impl TestFixture {
fn _which<T: AsRef<OsStr>>(f: &TestFixture, path: T) -> which::Result<which::CanonicalPath> {
which::CanonicalPath::new_in(path, Some(f.paths.clone()), f.tempdir.path())
}
fn _which_uncanonicalized<T: AsRef<OsStr>>(f: &TestFixture, path: T) -> which::Result<PathBuf> {
which::which_in(path, Some(f.paths.clone()), f.tempdir.path())
}

fn _which_all<'a, T: AsRef<OsStr> + 'a>(
f: &'a TestFixture,
Expand Down Expand Up @@ -411,6 +414,21 @@ fn test_which_relative_leading_dot() {
);
}

#[test]
#[cfg(unix)]
fn test_which_relative_leading_dot_uncanonicalized() {
let f = TestFixture::new();

let actual = _which_uncanonicalized(&f, "./b/bin").unwrap();
assert_eq!(actual, f.bins[3].canonicalize().unwrap());

assert!(
!actual.display().to_string().contains("/./"),
"'{}' should not contain a CurDir component",
actual.display()
);
}

#[test]
#[cfg(unix)]
fn test_which_non_executable() {
Expand Down

0 comments on commit 87acc08

Please sign in to comment.