From 26c274d785bafd2bb003a4426d6b749ede71882b Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 16 Dec 2024 07:42:13 +0100 Subject: [PATCH 1/3] feat: add `Prepare::with_shell_disallow_manual_argument_splitting()`. That way it's also possible to forcefully turn off manual argument splitting. --- gix-command/src/lib.rs | 6 ++++++ gix-command/tests/command.rs | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/gix-command/src/lib.rs b/gix-command/src/lib.rs index 4ad7b5c2082..db0ad20b68f 100644 --- a/gix-command/src/lib.rs +++ b/gix-command/src/lib.rs @@ -136,6 +136,12 @@ mod prepare { self.with_shell() } + /// Use a shell, but prohibit splitting arguments by hand even if this could be safely done without a shell. + pub fn with_shell_disallow_manual_argument_splitting(mut self) -> Self { + self.allow_manual_arg_splitting = false; + self.with_shell() + } + /// Configure the process to use `stdio` for _stdin. pub fn stdin(mut self, stdio: Stdio) -> Self { self.stdin = stdio; diff --git a/gix-command/tests/command.rs b/gix-command/tests/command.rs index bb69876278c..86fac932504 100644 --- a/gix-command/tests/command.rs +++ b/gix-command/tests/command.rs @@ -322,6 +322,14 @@ mod prepare { ); } + #[test] + fn single_and_complex_arguments_without_auto_split() { + let cmd = std::process::Command::from( + gix_command::prepare("ls --foo=\"a b\"").with_shell_disallow_manual_argument_splitting(), + ); + assert_eq!(format!("{cmd:?}"), quoted(&[SH, "-c", r#"ls --foo=\"a b\""#, "--"])); + } + #[test] fn single_and_complex_arguments_will_not_auto_split_on_special_characters() { let cmd = From 4d9bded0f77f24a4596d2a0949968293962961cc Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 16 Dec 2024 07:51:38 +0100 Subject: [PATCH 2/3] fix!: rename `Prepare::with_shell_allow_argument_splitting()` to `Prepare::with_shell_allow_manual_argument_splitting()` --- gix-command/src/lib.rs | 2 +- gix-command/tests/command.rs | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/gix-command/src/lib.rs b/gix-command/src/lib.rs index db0ad20b68f..ae2d261149b 100644 --- a/gix-command/src/lib.rs +++ b/gix-command/src/lib.rs @@ -131,7 +131,7 @@ mod prepare { /// Use a shell, but try to split arguments by hand if this can be safely done without a shell. /// /// If that's not the case, use a shell instead. - pub fn with_shell_allow_argument_splitting(mut self) -> Self { + pub fn with_shell_allow_manual_argument_splitting(mut self) -> Self { self.allow_manual_arg_splitting = true; self.with_shell() } diff --git a/gix-command/tests/command.rs b/gix-command/tests/command.rs index 86fac932504..e44929ed149 100644 --- a/gix-command/tests/command.rs +++ b/gix-command/tests/command.rs @@ -246,7 +246,7 @@ mod prepare { #[test] fn multiple_arguments_in_one_line_with_auto_split() { let cmd = std::process::Command::from( - gix_command::prepare("echo first second third").with_shell_allow_argument_splitting(), + gix_command::prepare("echo first second third").with_shell_allow_manual_argument_splitting(), ); assert_eq!( format!("{cmd:?}"), @@ -313,8 +313,9 @@ mod prepare { #[test] fn single_and_complex_arguments_with_auto_split() { - let cmd = - std::process::Command::from(gix_command::prepare("ls --foo=\"a b\"").with_shell_allow_argument_splitting()); + let cmd = std::process::Command::from( + gix_command::prepare("ls --foo=\"a b\"").with_shell_allow_manual_argument_splitting(), + ); assert_eq!( format!("{cmd:?}"), format!(r#""ls" "--foo=a b""#), @@ -332,8 +333,9 @@ mod prepare { #[test] fn single_and_complex_arguments_will_not_auto_split_on_special_characters() { - let cmd = - std::process::Command::from(gix_command::prepare("ls --foo=~/path").with_shell_allow_argument_splitting()); + let cmd = std::process::Command::from( + gix_command::prepare("ls --foo=~/path").with_shell_allow_manual_argument_splitting(), + ); assert_eq!( format!("{cmd:?}"), format!(r#""{SH}" "-c" "ls --foo=~/path" "--""#), From c67770ff118f00846936117fccc2c59ca3220f6e Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 16 Dec 2024 07:56:59 +0100 Subject: [PATCH 3/3] adapt to changes in `gix-command` --- gix-credentials/src/program/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gix-credentials/src/program/mod.rs b/gix-credentials/src/program/mod.rs index 8721e95f764..2d216044997 100644 --- a/gix-credentials/src/program/mod.rs +++ b/gix-credentials/src/program/mod.rs @@ -82,7 +82,7 @@ impl Program { args.insert_str(0, git_program.to_string_lossy().as_ref()); gix_command::prepare(gix_path::from_bstr(args.as_bstr()).into_owned()) .arg(action.as_arg(true)) - .with_shell_allow_argument_splitting() + .with_shell_allow_manual_argument_splitting() .into() } Kind::ExternalShellScript(for_shell)