Skip to content

Commit 8766f51

Browse files
committed
Try escaping, that's a cool trick
I couldn’t find a go shell escaping lib to do this for me so I just did spaces.
1 parent 867eadf commit 8766f51

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

s3secrets-helper/secrets/secrets.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,20 +205,29 @@ func handleGitCredentials(conf Config, results <-chan getResult) error {
205205
continue
206206
}
207207
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)
212215
}
213216
if len(helpers) == 0 {
214217
return nil
215218
}
216219

220+
// Build an environment variable for interpretation by a shell
217221
var singleQuotedHelpers []string
218-
for helper := range helpers {
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+
219229
singleQuotedHelpers = append(singleQuotedHelpers, "'" + helper + "'")
220230
}
221-
222231
env := "GIT_CONFIG_PARAMETERS=\"" + strings.Join(singleQuotedHelpers, " ") + "\"\n"
223232

224233
if _, err := io.WriteString(conf.EnvSink, env); err != nil {

0 commit comments

Comments
 (0)