Skip to content
This repository was archived by the owner on Jan 12, 2022. It is now read-only.

Commit 84bf91f

Browse files
committed
rudimentry support for nested quotes
1 parent b9324c6 commit 84bf91f

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

godotenv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func parseValue(value string) string {
234234
last := string(value[len(value)-1:])
235235
if first == last && strings.ContainsAny(first, `"'`) {
236236
// pull the quotes off the edges
237-
value = strings.Trim(value, `"'`)
237+
value = value[1 : len(value)-1]
238238
// handle escapes
239239
escapeRegex := regexp.MustCompile(`\\.`)
240240
value = escapeRegex.ReplaceAllStringFunc(value, func(match string) string {

godotenv_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ func TestParsing(t *testing.T) {
199199
// parses escaped double quotes
200200
parseAndCompare(t, `FOO="escaped\"bar"`, "FOO", `escaped"bar`)
201201

202+
// parses single quotes inside double quotes
203+
parseAndCompare(t, `FOO="'d'"`, "FOO", `'d'`)
204+
202205
// parses yaml style options
203206
parseAndCompare(t, "OPTION_A: 1", "OPTION_A", "1")
204207

0 commit comments

Comments
 (0)