@@ -15,12 +15,25 @@ mod prepare {
15
15
let cmd = std:: process:: Command :: from ( gix_command:: prepare ( "" ) ) ;
16
16
assert_eq ! ( format!( "{cmd:?}" ) , "\" \" " ) ;
17
17
}
18
+
18
19
#[ test]
19
20
fn single_and_multiple_arguments ( ) {
20
21
let cmd = std:: process:: Command :: from ( gix_command:: prepare ( "ls" ) . arg ( "first" ) . args ( [ "second" , "third" ] ) ) ;
21
22
assert_eq ! ( format!( "{cmd:?}" ) , quoted( & [ "ls" , "first" , "second" , "third" ] ) ) ;
22
23
}
23
24
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
+
24
37
#[ test]
25
38
fn single_and_multiple_arguments_as_part_of_command ( ) {
26
39
let cmd = std:: process:: Command :: from ( gix_command:: prepare ( "ls first second third" ) ) ;
@@ -36,7 +49,11 @@ mod prepare {
36
49
let cmd = std:: process:: Command :: from ( gix_command:: prepare ( "ls first second third" ) . with_shell ( ) ) ;
37
50
assert_eq ! (
38
51
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
+ } ,
40
57
"with shell, this works as it performs word splitting"
41
58
) ;
42
59
}
@@ -46,17 +63,43 @@ mod prepare {
46
63
let cmd = std:: process:: Command :: from ( gix_command:: prepare ( "ls --foo \" a b\" " ) . arg ( "additional" ) . with_shell ( ) ) ;
47
64
assert_eq ! (
48
65
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
+ } ,
50
71
"with shell, this works as it performs word splitting"
51
72
) ;
52
73
}
53
74
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
+
54
97
#[ test]
55
98
fn tilde_path_and_multiple_arguments_as_part_of_command_with_shell ( ) {
56
99
let cmd = std:: process:: Command :: from ( gix_command:: prepare ( "~/bin/exe --foo \" a b\" " ) . with_shell ( ) ) ;
57
100
assert_eq ! (
58
101
format!( "{cmd:?}" ) ,
59
- format!( " \ " {SH}\" \ " -c\" \ " ~/bin/exe --foo \\ \ " a b\\ \" \" \ " --\" " ) ,
102
+ format!( r#" "{SH}" "-c" "~/bin/exe --foo \"a b\"" "--""# ) ,
60
103
"this always needs a shell as we need tilde expansion"
61
104
) ;
62
105
}
0 commit comments