Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (
)

// originally ported from github.com/joho/godotenv
const doubleQuoteSpecialChars = "\\\n\r\"!$`"
// exclamation point removed; ruby and node dotenv libraries do not escape it
const doubleQuoteSpecialChars = "\\\n\r\"$`"

var (
// envCmd represents the env command
Expand Down
23 changes: 23 additions & 0 deletions cmd/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,26 @@ func Test_sanitizeKey(t *testing.T) {
})
}
}

func Test_doubleQuoteEscape(t *testing.T) {
tests := []struct {
given string
expected string
}{
{given: "ordinary string", expected: "ordinary string"},
{given: `string\with\backslashes`, expected: `string\\with\\backslashes`},
{given: "string\nwith\nnewlines", expected: `string\nwith\nnewlines`},
{given: "string\rwith\rcarriage returns", expected: `string\rwith\rcarriage returns`},
{given: `string"with"quotation marks`, expected: `string\"with\"quotation marks`},
{given: `string!with!excl`, expected: `string!with!excl`}, // do not escape !
{given: `string$with$dollar signs`, expected: `string\$with\$dollar signs`},
}

for _, tt := range tests {
t.Run("test sanitizing key names", func(t *testing.T) {
if got := doubleQuoteEscape(tt.given); got != tt.expected {
t.Errorf("shellName error: want %q, got %q", tt.expected, got)
}
})
}
}