Skip to content

Commit ca69f16

Browse files
committed
go: double-quote GIT_CONFIG_PARAMETERS; eval keeps inner single-quotes
1 parent d116acb commit ca69f16

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

s3secrets-helper/secrets/secrets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func handleGitCredentials(conf Config, results <-chan getResult) error {
209209
if len(helpers) == 0 {
210210
return nil
211211
}
212-
env := "GIT_CONFIG_PARAMETERS=" + strings.Join(helpers, " ") + "\n"
212+
env := "GIT_CONFIG_PARAMETERS=\"" + strings.Join(helpers, " ") + "\"\n"
213213
if _, err := io.WriteString(conf.EnvSink, env); err != nil {
214214
return fmt.Errorf("writing GIT_CONFIG_PARAMETERS env: %w", err)
215215
}

s3secrets-helper/secrets/secrets_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ func TestRun(t *testing.T) {
115115

116116
// verify env
117117
gitCredentialHelpers := strings.Join([]string{
118-
"'credential.helper=/path/to/git-credential-s3-secrets bkt git-credentials'",
119-
"'credential.helper=/path/to/git-credential-s3-secrets bkt pipeline/git-credentials'",
120-
}, " ") + "\n"
118+
`'credential.helper=/path/to/git-credential-s3-secrets bkt git-credentials'`,
119+
`'credential.helper=/path/to/git-credential-s3-secrets bkt pipeline/git-credentials'`,
120+
}, " ")
121121
expected := strings.Join([]string{
122122
// because an SSH key was found, ssh-agent was started:
123123
"SSH_AUTH_SOCK=/path/to/socket; export SSH_AUTH_SOCK;",
@@ -128,8 +128,9 @@ func TestRun(t *testing.T) {
128128
"B=two",
129129
"C=three",
130130
// because git-credentials were found:
131-
"GIT_CONFIG_PARAMETERS=" + gitCredentialHelpers,
132-
}, "\n")
131+
// (wrap in double quotes so that bash eval doesn't consume the inner single quote.
132+
`GIT_CONFIG_PARAMETERS="` + gitCredentialHelpers + `"`,
133+
}, "\n") + "\n"
133134
if actual := envSink.String(); expected != actual {
134135
t.Errorf("unexpected env written:\n-%q\n+%q", expected, actual)
135136
}

0 commit comments

Comments
 (0)