Skip to content

Commit

Permalink
Quote multi-line values in @SUMMONENVFILE
Browse files Browse the repository at this point in the history
  • Loading branch information
mcanevet committed Feb 5, 2021
1 parent cec67d2 commit 39656f6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions internal/command/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os/exec"
"path/filepath"
"sort"
"strconv"
"strings"
"sync"
"syscall"
Expand Down Expand Up @@ -199,9 +200,14 @@ func formatForEnv(key string, value string, spec secretsyml.SecretSpec, tempFact
func joinEnv(env map[string]string) string {
var envs []string
for k, v := range env {
envs = append(envs, fmt.Sprintf("%s=%s", k, v))
if strings.Contains(v, "\n") {
keyEq := []byte(fmt.Sprintf("%s=", k))
envs = append(envs, string(strconv.AppendQuote(keyEq, v)))
} else {
envs = append(envs, fmt.Sprintf("%s=%s", k, v))
}
}

// Sort to ensure predictable results
sort.Strings(envs)

Expand Down
4 changes: 2 additions & 2 deletions internal/command/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ func TestFormatForEnvString(t *testing.T) {

func TestJoinEnv(t *testing.T) {
Convey("adds a trailing newline", t, func() {
result := joinEnv(map[string]string{"foo": "bar", "baz": "qux"})
So(result, ShouldEqual, "baz=qux\nfoo=bar\n")
result := joinEnv(map[string]string{"foo": "bar\nfoo", "baz": "qux"})
So(result, ShouldEqual, "baz=qux\nfoo=\"bar\\nfoo\"\n")
})
}

Expand Down

0 comments on commit 39656f6

Please sign in to comment.