From adbbbf46f2711bd07eb9760b9cdd4c5da73e07e7 Mon Sep 17 00:00:00 2001 From: Arthur Baars Date: Mon, 10 Mar 2025 10:39:15 +0000 Subject: [PATCH 1/2] Add test case for credential.helper containing slashes --- src/cred.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cred.rs b/src/cred.rs index b1f15cab13..b2fa8a64ce 100644 --- a/src/cred.rs +++ b/src/cred.rs @@ -578,13 +578,13 @@ echo username=c return; } // shell scripts don't work on Windows let td = TempDir::new().unwrap(); - let path = td.path().join("git-credential-script"); + let path = td.path().join("git-credential-some-script"); File::create(&path) .unwrap() .write( br"\ #!/bin/sh -echo username=c +echo username=$1 ", ) .unwrap(); @@ -596,14 +596,14 @@ echo username=c env::set_var("PATH", &env::join_paths(paths).unwrap()); let cfg = test_cfg! { - "credential.https://example.com.helper" => "script", + "credential.https://example.com.helper" => "some-script \"value/with\\slashes\"", "credential.helper" => "!f() { echo username=a; echo password=b; }; f" }; let (u, p) = CredentialHelper::new("https://example.com/foo/bar") .config(&cfg) .execute() .unwrap(); - assert_eq!(u, "c"); + assert_eq!(u, "value/with\\slashes"); assert_eq!(p, "b"); } From c776e8d688ff2772f80a2dd440a986896a6c29b4 Mon Sep 17 00:00:00 2001 From: Arthur Baars Date: Wed, 5 Mar 2025 11:33:33 +0100 Subject: [PATCH 2/2] Fix CredentialHelper::add_command Fixes https://github.com/rust-lang/git2-rs/issues/1136 --- src/cred.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cred.rs b/src/cred.rs index b2fa8a64ce..3def56ab6e 100644 --- a/src/cred.rs +++ b/src/cred.rs @@ -299,7 +299,7 @@ impl CredentialHelper { if cmd.starts_with('!') { self.commands.push(cmd[1..].to_string()); - } else if cmd.contains("/") || cmd.contains("\\") { + } else if is_absolute_path(cmd) { self.commands.push(cmd.to_string()); } else { self.commands.push(format!("git credential-{}", cmd)); @@ -481,6 +481,12 @@ impl CredentialHelper { } } +fn is_absolute_path(path: &str) -> bool { + path.starts_with('/') + || path.starts_with('\\') + || cfg!(windows) && path.chars().nth(1).is_some_and(|x| x == ':') +} + #[cfg(test)] mod test { use std::env;