Skip to content

Commit 39656f6

Browse files
committed
Quote multi-line values in @SUMMONENVFILE
1 parent cec67d2 commit 39656f6

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

internal/command/action.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os/exec"
88
"path/filepath"
99
"sort"
10+
"strconv"
1011
"strings"
1112
"sync"
1213
"syscall"
@@ -199,9 +200,14 @@ func formatForEnv(key string, value string, spec secretsyml.SecretSpec, tempFact
199200
func joinEnv(env map[string]string) string {
200201
var envs []string
201202
for k, v := range env {
202-
envs = append(envs, fmt.Sprintf("%s=%s", k, v))
203+
if strings.Contains(v, "\n") {
204+
keyEq := []byte(fmt.Sprintf("%s=", k))
205+
envs = append(envs, string(strconv.AppendQuote(keyEq, v)))
206+
} else {
207+
envs = append(envs, fmt.Sprintf("%s=%s", k, v))
208+
}
203209
}
204-
210+
205211
// Sort to ensure predictable results
206212
sort.Strings(envs)
207213

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, "baz=qux\nfoo=bar\n")
84+
result := joinEnv(map[string]string{"foo": "bar\nfoo", "baz": "qux"})
85+
So(result, ShouldEqual, "baz=qux\nfoo=\"bar\\nfoo\"\n")
8686
})
8787
}
8888

0 commit comments

Comments
 (0)