File tree Expand file tree Collapse file tree 2 files changed +30
-13
lines changed Expand file tree Collapse file tree 2 files changed +30
-13
lines changed Original file line number Diff line number Diff line change @@ -293,4 +293,23 @@ fn cli_issue_280() {
293
293
. arg ( "." )
294
294
. assert ( )
295
295
. success ( ) ;
296
+
297
+ // Handle special case of just ./ for path argument.
298
+ Command :: cargo_bin ( "yr" )
299
+ . unwrap ( )
300
+ . arg ( "scan" )
301
+ . arg ( "src/tests/testdata/foo.yar" )
302
+ . arg ( "./" )
303
+ . assert ( )
304
+ . success ( ) ;
305
+
306
+ // Handle special case of just .\ for path argument.
307
+ #[ cfg( target_os = "windows" ) ]
308
+ Command :: cargo_bin ( "yr" )
309
+ . unwrap ( )
310
+ . arg ( "scan" )
311
+ . arg ( "src/tests/testdata/foo.yar" )
312
+ . arg ( r#".\"# )
313
+ . assert ( )
314
+ . success ( ) ;
296
315
}
Original file line number Diff line number Diff line change @@ -199,21 +199,19 @@ impl<'a> Walker<'a> {
199
199
F : FnMut ( & Path ) -> anyhow:: Result < ( ) > ,
200
200
E : FnMut ( anyhow:: Error ) -> anyhow:: Result < ( ) > ,
201
201
{
202
- // Strip the ./ prefix (.\ in Windows), if present. This is a
203
- // workaround for a bug in globwalk that causes a panic.
202
+ // Strip the ./ prefix (.\ in Windows), if present. Except for ".",
203
+ // "./" and ".\". This is a workaround for a bug in globwalk that
204
+ // causes a panic.
204
205
// https://github.com/VirusTotal/yara-x/issues/280
205
206
// https://github.com/Gilnaa/globwalk/issues/28
206
- //
207
- // Only perform the strip if the path is not exactly "." - this allows
208
- // users to run "yr scan rules.yara ." to scan all the files in the
209
- // current directory.
210
- let path = if self . path . as_os_str ( ) . ne ( "." ) {
211
- #[ cfg( not( target_os = "windows" ) ) ]
212
- let path = self . path . strip_prefix ( "./" ) . unwrap_or ( self . path ) ;
213
-
214
- #[ cfg( target_os = "windows" ) ]
215
- let path = self . path . strip_prefix ( r#".\"# ) . unwrap_or ( self . path ) ;
216
- path
207
+ let path = if self . path . as_os_str ( ) . len ( ) > 2 {
208
+ self . path
209
+ . strip_prefix ( if cfg ! ( target_os = "windows" ) {
210
+ r#".\"#
211
+ } else {
212
+ "./"
213
+ } )
214
+ . unwrap_or ( self . path )
217
215
} else {
218
216
self . path
219
217
} ;
You can’t perform that action at this time.
0 commit comments