Skip to content

Commit a5ba202

Browse files
committed
fix: Prepare::with_shell() now assures manual argument splitting isn't done on Windows either.
That way `with_shell()` means what it says, previously it was a trap that was impossible to get right on Windows.
1 parent 1bccbfe commit a5ba202

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

gix-command/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,13 @@ mod prepare {
134134
/// commands are always executed verbatim and directly, without the use of a shell. (But
135135
/// see [`command_may_be_shell_script()`](Self::command_may_be_shell_script()) on other
136136
/// methods that call that method.)
137+
///
138+
/// We also disallow manual argument splitting
139+
/// (see [`command_may_be_shell_script_disallow_manual_argument_splitting`](Self::command_may_be_shell_script_disallow_manual_argument_splitting()))
140+
/// to assure a shell is indeed used, no matter what.
137141
pub fn with_shell(mut self) -> Self {
138142
self.use_shell = true;
143+
self.allow_manual_arg_splitting = false;
139144
self
140145
}
141146

gix-command/tests/command.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ mod prepare {
319319
let sh = *SH;
320320
format!(r#""{sh}" "-c" "ls --foo \"a b\" \"$@\"" "--" "additional""#)
321321
},
322-
"with shell, this works as it performs word splitting"
322+
"with shell, this works as it performs word splitting, on windows we can avoid the shell"
323323
);
324324
}
325325

@@ -345,12 +345,7 @@ mod prepare {
345345

346346
#[test]
347347
fn single_and_simple_arguments_without_auto_split_with_shell() {
348-
let cmd = std::process::Command::from(
349-
gix_command::prepare("ls")
350-
.arg("--foo=a b")
351-
.command_may_be_shell_script_disallow_manual_argument_splitting()
352-
.with_shell(),
353-
);
348+
let cmd = std::process::Command::from(gix_command::prepare("ls").arg("--foo=a b").with_shell());
354349
assert_eq!(
355350
format!("{cmd:?}"),
356351
quoted(&[*SH, "-c", r#"ls \"$@\""#, "--", "--foo=a b"])
@@ -362,7 +357,6 @@ mod prepare {
362357
let cmd = std::process::Command::from(
363358
gix_command::prepare("ls")
364359
.arg("--foo=a b")
365-
.command_may_be_shell_script_disallow_manual_argument_splitting()
366360
.with_shell()
367361
.with_quoted_command(),
368362
);
@@ -378,7 +372,6 @@ mod prepare {
378372
let cmd = std::process::Command::from(
379373
gix_command::prepare(r"C:\Users\O'Shaughnessy\with space.exe")
380374
.arg("--foo='a b'")
381-
.command_may_be_shell_script_disallow_manual_argument_splitting()
382375
.with_shell()
383376
.with_quoted_command(),
384377
);

0 commit comments

Comments
 (0)