@@ -299,7 +299,7 @@ impl CredentialHelper {
299
299
300
300
if cmd. starts_with ( '!' ) {
301
301
self . commands . push ( cmd[ 1 ..] . to_string ( ) ) ;
302
- } else if cmd . contains ( "/" ) || cmd. contains ( " \\ " ) {
302
+ } else if is_absolute_path ( cmd) {
303
303
self . commands . push ( cmd. to_string ( ) ) ;
304
304
} else {
305
305
self . commands . push ( format ! ( "git credential-{}" , cmd) ) ;
@@ -481,6 +481,12 @@ impl CredentialHelper {
481
481
}
482
482
}
483
483
484
+ fn is_absolute_path ( path : & str ) -> bool {
485
+ path. starts_with ( '/' )
486
+ || path. starts_with ( '\\' )
487
+ || cfg ! ( windows) && path. chars ( ) . nth ( 1 ) . is_some_and ( |x| x == ':' )
488
+ }
489
+
484
490
#[ cfg( test) ]
485
491
mod test {
486
492
use std:: env;
@@ -578,13 +584,13 @@ echo username=c
578
584
return ;
579
585
} // shell scripts don't work on Windows
580
586
let td = TempDir :: new ( ) . unwrap ( ) ;
581
- let path = td. path ( ) . join ( "git-credential-script" ) ;
587
+ let path = td. path ( ) . join ( "git-credential-some- script" ) ;
582
588
File :: create ( & path)
583
589
. unwrap ( )
584
590
. write (
585
591
br"\
586
592
#!/bin/sh
587
- echo username=c
593
+ echo username=$1
588
594
" ,
589
595
)
590
596
. unwrap ( ) ;
@@ -596,14 +602,14 @@ echo username=c
596
602
env:: set_var ( "PATH" , & env:: join_paths ( paths) . unwrap ( ) ) ;
597
603
598
604
let cfg = test_cfg ! {
599
- "credential.https://example.com.helper" => "script" ,
605
+ "credential.https://example.com.helper" => "some- script \" value/with \\ slashes \" " ,
600
606
"credential.helper" => "!f() { echo username=a; echo password=b; }; f"
601
607
} ;
602
608
let ( u, p) = CredentialHelper :: new ( "https://example.com/foo/bar" )
603
609
. config ( & cfg)
604
610
. execute ( )
605
611
. unwrap ( ) ;
606
- assert_eq ! ( u, "c " ) ;
612
+ assert_eq ! ( u, "value/with \\ slashes " ) ;
607
613
assert_eq ! ( p, "b" ) ;
608
614
}
609
615
0 commit comments