@@ -205,15 +205,31 @@ func handleGitCredentials(conf Config, results <-chan getResult) error {
205
205
continue
206
206
}
207
207
log .Printf ("Adding git-credentials in %s/%s as a credential helper" , r .bucket , r .key )
208
- helpers = append (helpers , fmt .Sprintf (
209
- "'credential.helper=%s %s %s'" ,
210
- conf .GitCredentialHelper , r .bucket , r .key ,
211
- ))
208
+
209
+ // Replace spaces ' ' in the helper path with an escaped space '\ '
210
+ escapedCredentialHelper := strings .ReplaceAll (conf .GitCredentialHelper , " " , "\\ " )
211
+
212
+ helper := fmt .Sprintf ("credential.helper=%s %s %s" , escapedCredentialHelper , r .bucket , r .key )
213
+
214
+ helpers = append (helpers , helper )
212
215
}
213
216
if len (helpers ) == 0 {
214
217
return nil
215
218
}
216
- env := "GIT_CONFIG_PARAMETERS=\" " + strings .Join (helpers , " " ) + "\" \n "
219
+
220
+ // Build an environment variable for interpretation by a shell
221
+ var singleQuotedHelpers []string
222
+ for _ , helper := range helpers {
223
+ // Escape any escape sequences, the shell will interpret the first level
224
+ // of escaping.
225
+
226
+ // Replace backslash '\' with double backslash '\\'
227
+ helper = strings .ReplaceAll (helper , "\\ " , "\\ \\ " )
228
+
229
+ singleQuotedHelpers = append (singleQuotedHelpers , "'" + helper + "'" )
230
+ }
231
+ env := "GIT_CONFIG_PARAMETERS=\" " + strings .Join (singleQuotedHelpers , " " ) + "\" \n "
232
+
217
233
if _ , err := io .WriteString (conf .EnvSink , env ); err != nil {
218
234
return fmt .Errorf ("writing GIT_CONFIG_PARAMETERS env: %w" , err )
219
235
}
0 commit comments