Skip to content

Commit fa1dfb6

Browse files
committed
Don't quote absolute path helper commands
Quoting treats the full command as the path to binary, which prevents arguments from being provided. According to the [Git documentation][git-docs] arguments should be accepted. This also [matches the behaviour][git-source] of git itself. [git-docs]: https://git-scm.com/docs/api-credentials#_credential_helpers [git-source]: https://github.com/git/git/blob/ca1b4116483b397e78483376296bcd23916ab553/credential.c#L258-L261
1 parent 718799c commit fa1dfb6

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/cred.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl CredentialHelper {
257257
self.commands.push(cmd[1..].to_string());
258258
} else if cmd.starts_with('/') || cmd.starts_with('\\') ||
259259
cmd[1..].starts_with(":\\") {
260-
self.commands.push(format!("\"{}\"", cmd));
260+
self.commands.push(cmd.to_string());
261261
} else {
262262
self.commands.push(format!("git credential-{}", cmd));
263263
}
@@ -522,6 +522,26 @@ echo username=c
522522
.execute().is_none());
523523
}
524524

525+
#[test]
526+
fn credential_helper7() {
527+
let td = TempDir::new("git2-rs").unwrap();
528+
let path = td.path().join("script");
529+
File::create(&path).unwrap().write(br"\
530+
#!/bin/sh
531+
echo username=$1
532+
echo password=$2
533+
").unwrap();
534+
chmod(&path);
535+
let cfg = test_cfg! {
536+
"credential.helper" => &format!("{} a b", path.display())
537+
};
538+
let (u, p) = CredentialHelper::new("https://example.com/foo/bar")
539+
.config(&cfg)
540+
.execute().unwrap();
541+
assert_eq!(u, "a");
542+
assert_eq!(p, "b");
543+
}
544+
525545
#[test]
526546
fn ssh_key_from_memory() {
527547
let cred = Cred::ssh_key_from_memory(

0 commit comments

Comments
 (0)