@@ -15,12 +15,25 @@ mod prepare {
1515 let cmd = std:: process:: Command :: from ( gix_command:: prepare ( "" ) ) ;
1616 assert_eq ! ( format!( "{cmd:?}" ) , "\" \" " ) ;
1717 }
18+
1819 #[ test]
1920 fn single_and_multiple_arguments ( ) {
2021 let cmd = std:: process:: Command :: from ( gix_command:: prepare ( "ls" ) . arg ( "first" ) . args ( [ "second" , "third" ] ) ) ;
2122 assert_eq ! ( format!( "{cmd:?}" ) , quoted( & [ "ls" , "first" , "second" , "third" ] ) ) ;
2223 }
2324
25+ #[ test]
26+ fn multiple_arguments_in_one_line_with_auto_split ( ) {
27+ let cmd = std:: process:: Command :: from (
28+ gix_command:: prepare ( "echo first second third" ) . with_shell_allow_argument_splitting ( ) ,
29+ ) ;
30+ assert_eq ! (
31+ format!( "{cmd:?}" ) ,
32+ quoted( & [ "echo" , "first" , "second" , "third" ] ) ,
33+ "we split by hand which works unless one tries to rely on shell-builtins (which we can't detect)"
34+ ) ;
35+ }
36+
2437 #[ test]
2538 fn single_and_multiple_arguments_as_part_of_command ( ) {
2639 let cmd = std:: process:: Command :: from ( gix_command:: prepare ( "ls first second third" ) ) ;
@@ -36,7 +49,11 @@ mod prepare {
3649 let cmd = std:: process:: Command :: from ( gix_command:: prepare ( "ls first second third" ) . with_shell ( ) ) ;
3750 assert_eq ! (
3851 format!( "{cmd:?}" ) ,
39- quoted( & [ SH , "-c" , "ls first second third" , "--" ] ) ,
52+ if cfg!( windows) {
53+ quoted( & [ "ls" , "first" , "second" , "third" ] )
54+ } else {
55+ quoted( & [ SH , "-c" , "ls first second third" , "--" ] )
56+ } ,
4057 "with shell, this works as it performs word splitting"
4158 ) ;
4259 }
@@ -46,17 +63,43 @@ mod prepare {
4663 let cmd = std:: process:: Command :: from ( gix_command:: prepare ( "ls --foo \" a b\" " ) . arg ( "additional" ) . with_shell ( ) ) ;
4764 assert_eq ! (
4865 format!( "{cmd:?}" ) ,
49- format!( "\" {SH}\" \" -c\" \" ls --foo \\ \" a b\\ \" \\ \" $@\\ \" \" \" --\" \" additional\" " ) ,
66+ if cfg!( windows) {
67+ quoted( & [ "ls" , "--foo" , "a b" , "additional" ] )
68+ } else {
69+ format!( r#""{SH}" "-c" "ls --foo \"a b\" \"$@\"" "--" "additional""# )
70+ } ,
5071 "with shell, this works as it performs word splitting"
5172 ) ;
5273 }
5374
75+ #[ test]
76+ fn single_and_complex_arguments_with_auto_split ( ) {
77+ let cmd =
78+ std:: process:: Command :: from ( gix_command:: prepare ( "ls --foo=\" a b\" " ) . with_shell_allow_argument_splitting ( ) ) ;
79+ assert_eq ! (
80+ format!( "{cmd:?}" ) ,
81+ format!( r#""ls" "--foo=a b""# ) ,
82+ "splitting can also handle quotes"
83+ ) ;
84+ }
85+
86+ #[ test]
87+ fn single_and_complex_arguments_will_not_auto_split_on_special_characters ( ) {
88+ let cmd =
89+ std:: process:: Command :: from ( gix_command:: prepare ( "ls --foo=~/path" ) . with_shell_allow_argument_splitting ( ) ) ;
90+ assert_eq ! (
91+ format!( "{cmd:?}" ) ,
92+ format!( r#""{SH}" "-c" "ls --foo=~/path" "--""# ) ,
93+ "splitting can also handle quotes"
94+ ) ;
95+ }
96+
5497 #[ test]
5598 fn tilde_path_and_multiple_arguments_as_part_of_command_with_shell ( ) {
5699 let cmd = std:: process:: Command :: from ( gix_command:: prepare ( "~/bin/exe --foo \" a b\" " ) . with_shell ( ) ) ;
57100 assert_eq ! (
58101 format!( "{cmd:?}" ) ,
59- format!( " \ " {SH}\" \ " -c\" \ " ~/bin/exe --foo \\ \ " a b\\ \" \" \ " --\" " ) ,
102+ format!( r#" "{SH}" "-c" "~/bin/exe --foo \"a b\"" "--""# ) ,
60103 "this always needs a shell as we need tilde expansion"
61104 ) ;
62105 }
0 commit comments