Skip to content

Commit bc58b2c

Browse files
committed
Quote multi-line values in @SUMMONENVFILE
1 parent 5a73e4a commit bc58b2c

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

internal/command/action.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"os/exec"
88
"path/filepath"
9+
"strconv"
910
"strings"
1011
"sync"
1112
"syscall"
@@ -198,7 +199,12 @@ func formatForEnv(key string, value string, spec secretsyml.SecretSpec, tempFact
198199
func joinEnv(env map[string]string) string {
199200
var envs []string
200201
for k, v := range env {
201-
envs = append(envs, fmt.Sprintf("%s=%s", k, v))
202+
if strings.Contains(v, "\n") {
203+
keyEq := []byte(fmt.Sprintf("%s=", k))
204+
envs = append(envs, string(strconv.AppendQuote(keyEq, v)))
205+
} else {
206+
envs = append(envs, fmt.Sprintf("%s=%s", k, v))
207+
}
202208
}
203209
return strings.Join(envs, "\n") + "\n"
204210
}

internal/command/action_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ func TestFormatForEnvString(t *testing.T) {
8181

8282
func TestJoinEnv(t *testing.T) {
8383
Convey("adds a trailing newline", t, func() {
84-
result := joinEnv(map[string]string{"foo": "bar", "baz": "qux"})
85-
So(result, ShouldEqual, "foo=bar\nbaz=qux\n")
84+
result := joinEnv(map[string]string{"foo": "bar\nfoo", "baz": "qux"})
85+
So(result, ShouldEqual, "foo=\"bar\\nfoo\"\nbaz=qux\n")
8686
})
8787
}
8888

0 commit comments

Comments
 (0)