File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -321,16 +321,22 @@ impl Cmd {
321321 where
322322 O : AsRef < OsStr > ,
323323 {
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 ( ) ;
325331 if arg_str != IGNORE_CMD && !self . args . iter ( ) . any ( |cmd| * cmd != IGNORE_CMD ) {
326332 let v: Vec < & str > = arg_str. split ( '=' ) . collect ( ) ;
327333 if v. len ( ) == 2 && v[ 0 ] . chars ( ) . all ( |c| c. is_ascii_alphanumeric ( ) || c == '_' ) {
328334 self . vars . insert ( v[ 0 ] . into ( ) , v[ 1 ] . into ( ) ) ;
329335 return self ;
330336 }
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) ;
332338 }
333- self . args . push ( arg. as_ref ( ) . to_os_string ( ) ) ;
339+ self . args . push ( arg. to_os_string ( ) ) ;
334340 self
335341 }
336342
Original file line number Diff line number Diff line change @@ -249,3 +249,9 @@ fn test_path_as_var() {
249249 let dir2 = std:: path:: PathBuf :: from ( "/" ) ;
250250 assert_eq ! ( "/" , run_fun!( cd $dir2; pwd) . unwrap( ) ) ;
251251}
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