diff --git a/cmd/env.go b/cmd/env.go index 9ac7f50f..4653e468 100644 --- a/cmd/env.go +++ b/cmd/env.go @@ -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 diff --git a/cmd/env_test.go b/cmd/env_test.go index 2f489d07..760e093a 100644 --- a/cmd/env_test.go +++ b/cmd/env_test.go @@ -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) + } + }) + } +}