From a42a65518cade4f35102bd3378112edc859e8729 Mon Sep 17 00:00:00 2001 From: Oenning Date: Wed, 22 Mar 2017 13:05:44 +0000 Subject: [PATCH] allow empty_var --- fixtures/plain.env | 2 ++ godotenv.go | 21 ++++++++++++--------- godotenv_test.go | 2 ++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/fixtures/plain.env b/fixtures/plain.env index c983b06..43f7e44 100644 --- a/fixtures/plain.env +++ b/fixtures/plain.env @@ -3,3 +3,5 @@ OPTION_B=2 OPTION_C= 3 OPTION_D =4 OPTION_E = 5 +OPTION_F = +OPTION_G= \ No newline at end of file diff --git a/godotenv.go b/godotenv.go index 2551048..016acc1 100644 --- a/godotenv.go +++ b/godotenv.go @@ -212,20 +212,23 @@ func parseLine(line string) (key string, value string, err error) { // Parse the value value = splitString[1] + // trim value = strings.Trim(value, " ") // check if we've got quoted values - first := string(value[0:1]) - last := string(value[len(value)-1:]) - if first == last && strings.ContainsAny(first, `"'`) { - // pull the quotes off the edges - value = strings.Trim(value, `"'`) + if value != "" { + first := string(value[0:1]) + last := string(value[len(value)-1:]) + if first == last && strings.ContainsAny(first, `"'`) { + // pull the quotes off the edges + value = strings.Trim(value, `"'`) - // expand quotes - value = strings.Replace(value, `\"`, `"`, -1) - // expand newlines - value = strings.Replace(value, `\n`, "\n", -1) + // expand quotes + value = strings.Replace(value, `\"`, `"`, -1) + // expand newlines + value = strings.Replace(value, `\n`, "\n", -1) + } } return diff --git a/godotenv_test.go b/godotenv_test.go index ea22da3..0a1aff6 100644 --- a/godotenv_test.go +++ b/godotenv_test.go @@ -74,6 +74,8 @@ func TestReadPlainEnv(t *testing.T) { "OPTION_C": "3", "OPTION_D": "4", "OPTION_E": "5", + "OPTION_F": "", + "OPTION_G": "", } envMap, err := Read(envFileName)