diff --git a/cli/src/tests/mod.rs b/cli/src/tests/mod.rs index e4e7e1a6..5bbe28ce 100644 --- a/cli/src/tests/mod.rs +++ b/cli/src/tests/mod.rs @@ -284,4 +284,13 @@ fn cli_issue_280() { .arg("./src/tests/testdata/") .assert() .success(); + + // Handle special case of just . for path argument. + Command::cargo_bin("yr") + .unwrap() + .arg("scan") + .arg("src/tests/testdata/foo.yar") + .arg(".") + .assert() + .success(); } diff --git a/cli/src/walk.rs b/cli/src/walk.rs index 9d89f6b8..f7486f64 100644 --- a/cli/src/walk.rs +++ b/cli/src/walk.rs @@ -203,12 +203,20 @@ impl<'a> Walker<'a> { // workaround for a bug in globwalk that causes a panic. // https://github.com/VirusTotal/yara-x/issues/280 // https://github.com/Gilnaa/globwalk/issues/28 - - #[cfg(not(target_os = "windows"))] - let path = self.path.strip_prefix("./").unwrap_or(self.path); - - #[cfg(target_os = "windows")] - let path = self.path.strip_prefix(r#".\"#).unwrap_or(self.path); + // + // Only perform the strip if the path is not exactly "." - this allows + // users to run "yr scan rules.yara ." to scan all the files in the + // current directory. + let path = if self.path.as_os_str().ne(".") { + #[cfg(not(target_os = "windows"))] + let path = self.path.strip_prefix("./").unwrap_or(self.path); + + #[cfg(target_os = "windows")] + let path = self.path.strip_prefix(r#".\"#).unwrap_or(self.path); + path + } else { + self.path + }; let mut builder = if self.filters.is_empty() { globwalk::GlobWalkerBuilder::from_patterns(path, &["**"])