File tree 2 files changed +15
-3
lines changed
2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -321,16 +321,22 @@ impl Cmd {
321
321
where
322
322
O : AsRef < OsStr > ,
323
323
{
324
- let arg_str = arg. as_ref ( ) . to_string_lossy ( ) . to_string ( ) ;
324
+ let arg = arg. as_ref ( ) ;
325
+ if arg. is_empty ( ) {
326
+ // Skip empty arguments
327
+ return self ;
328
+ }
329
+
330
+ let arg_str = arg. to_string_lossy ( ) . to_string ( ) ;
325
331
if arg_str != IGNORE_CMD && !self . args . iter ( ) . any ( |cmd| * cmd != IGNORE_CMD ) {
326
332
let v: Vec < & str > = arg_str. split ( '=' ) . collect ( ) ;
327
333
if v. len ( ) == 2 && v[ 0 ] . chars ( ) . all ( |c| c. is_ascii_alphanumeric ( ) || c == '_' ) {
328
334
self . vars . insert ( v[ 0 ] . into ( ) , v[ 1 ] . into ( ) ) ;
329
335
return self ;
330
336
}
331
- self . in_cmd_map = CMD_MAP . lock ( ) . unwrap ( ) . contains_key ( arg. as_ref ( ) ) ;
337
+ self . in_cmd_map = CMD_MAP . lock ( ) . unwrap ( ) . contains_key ( arg) ;
332
338
}
333
- self . args . push ( arg. as_ref ( ) . to_os_string ( ) ) ;
339
+ self . args . push ( arg. to_os_string ( ) ) ;
334
340
self
335
341
}
336
342
Original file line number Diff line number Diff line change @@ -249,3 +249,9 @@ fn test_path_as_var() {
249
249
let dir2 = std:: path:: PathBuf :: from ( "/" ) ;
250
250
assert_eq ! ( "/" , run_fun!( cd $dir2; pwd) . unwrap( ) ) ;
251
251
}
252
+
253
+ #[ test]
254
+ fn test_empty_arg ( ) {
255
+ let opt = "" ;
256
+ assert ! ( run_cmd!( ls $opt) . is_ok( ) ) ;
257
+ }
You can’t perform that action at this time.
0 commit comments