Skip to content

Commit 26c274d

Browse files
committed
feat: add Prepare::with_shell_disallow_manual_argument_splitting().
That way it's also possible to forcefully turn off manual argument splitting.
1 parent cd9060a commit 26c274d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

gix-command/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ mod prepare {
136136
self.with_shell()
137137
}
138138

139+
/// Use a shell, but prohibit splitting arguments by hand even if this could be safely done without a shell.
140+
pub fn with_shell_disallow_manual_argument_splitting(mut self) -> Self {
141+
self.allow_manual_arg_splitting = false;
142+
self.with_shell()
143+
}
144+
139145
/// Configure the process to use `stdio` for _stdin.
140146
pub fn stdin(mut self, stdio: Stdio) -> Self {
141147
self.stdin = stdio;

gix-command/tests/command.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,14 @@ mod prepare {
322322
);
323323
}
324324

325+
#[test]
326+
fn single_and_complex_arguments_without_auto_split() {
327+
let cmd = std::process::Command::from(
328+
gix_command::prepare("ls --foo=\"a b\"").with_shell_disallow_manual_argument_splitting(),
329+
);
330+
assert_eq!(format!("{cmd:?}"), quoted(&[SH, "-c", r#"ls --foo=\"a b\""#, "--"]));
331+
}
332+
325333
#[test]
326334
fn single_and_complex_arguments_will_not_auto_split_on_special_characters() {
327335
let cmd =

0 commit comments

Comments
 (0)