From a905e995777b9f09a2234ffd7d5f0bf721cecee2 Mon Sep 17 00:00:00 2001 From: Alex Quick Date: Sun, 16 Jul 2017 18:43:49 -0400 Subject: [PATCH] fix panic with `"` as the value --- godotenv.go | 4 ++-- godotenv_test.go | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/godotenv.go b/godotenv.go index 172c4f5..8c6ff37 100644 --- a/godotenv.go +++ b/godotenv.go @@ -228,8 +228,8 @@ func parseValue(value string) string { // trim value = strings.Trim(value, " ") - // check if we've got quoted values - if value != "" { + // check if we've got quoted values or possible escapes + if len(value) > 1 { first := string(value[0:1]) last := string(value[len(value)-1:]) if first == last && strings.ContainsAny(first, `"'`) { diff --git a/godotenv_test.go b/godotenv_test.go index 4099201..d8f5890 100644 --- a/godotenv_test.go +++ b/godotenv_test.go @@ -252,6 +252,10 @@ func TestParsing(t *testing.T) { parseAndCompare(t, `FOO="bar\\\n\ b\az"`, "FOO", "bar\\\n baz") parseAndCompare(t, `FOO="bar\\r\ b\az"`, "FOO", "bar\\r baz") + parseAndCompare(t, `="value"`, "", "value") + parseAndCompare(t, `KEY="`, "KEY", "\"") + parseAndCompare(t, `KEY="value`, "KEY", "\"value") + // it 'throws an error if line format is incorrect' do // expect{env('lol$wut')}.to raise_error(Dotenv::FormatError) badlyFormattedLine := "lol$wut"