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

Lexiclean search directory so .. does not check the current directory #2236

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const DEFAULT_JUSTFILE_NAME: &str = JUSTFILE_NAMES[0];
pub(crate) const JUSTFILE_NAMES: [&str; 2] = ["justfile", ".justfile"];
const PROJECT_ROOT_CHILDREN: &[&str] = &[".bzr", ".git", ".hg", ".svn", "_darcs"];

#[derive(Debug)]
pub(crate) struct Search {
pub(crate) justfile: PathBuf,
pub(crate) working_directory: PathBuf,
Expand Down
7 changes: 4 additions & 3 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ impl Subcommand {
) {
let starting_path = match &config.search_config {
SearchConfig::FromInvocationDirectory => config.invocation_directory.clone(),
SearchConfig::FromSearchDirectory { search_directory } => {
env::current_dir().unwrap().join(search_directory)
}
SearchConfig::FromSearchDirectory { search_directory } => config
.invocation_directory
.join(search_directory)
.lexiclean(),
_ => unreachable!(),
};

Expand Down
16 changes: 16 additions & 0 deletions tests/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,22 @@ fn single_upwards() {
search_test(path, &["../"]);
}

#[test]
fn double_upwards() {
let tmp = temptree! {
justfile: "default:\n\techo ok",
foo: {
bar: {
justfile: "default:\n\techo foo",
},
},
};

let path = tmp.path().join("foo/bar");

search_test(path, &["../default"]);
}

#[test]
fn find_dot_justfile() {
Test::new()
Expand Down