From 7e3e1e2c6ce31914ef27b4a6336cbe7fa188ef71 Mon Sep 17 00:00:00 2001 From: Yannick Schutz Date: Fri, 7 Mar 2014 23:21:31 +0100 Subject: [PATCH] Use SplitN instead of split --- fixtures/equals.env | 2 ++ godotenv.go | 2 +- godotenv_test.go | 9 +++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 fixtures/equals.env diff --git a/fixtures/equals.env b/fixtures/equals.env new file mode 100644 index 0000000..594c532 --- /dev/null +++ b/fixtures/equals.env @@ -0,0 +1,2 @@ +export OPTION_A='postgres://localhost:5432/database?sslmode=disable' + diff --git a/godotenv.go b/godotenv.go index a421053..a75eb20 100644 --- a/godotenv.go +++ b/godotenv.go @@ -138,7 +138,7 @@ func parseLine(line string) (key string, value string, err error) { } // now split key from value - splitString := strings.Split(line, "=") + splitString := strings.SplitN(line, "=", 2) if len(splitString) != 2 { // try yaml mode! diff --git a/godotenv_test.go b/godotenv_test.go index 381be3e..5af8564 100644 --- a/godotenv_test.go +++ b/godotenv_test.go @@ -93,6 +93,15 @@ func TestLoadExportedEnv(t *testing.T) { loadEnvAndCompareValues(t, envFileName, expectedValues) } +func TestLoadEqualsEnv(t *testing.T) { + envFileName := "fixtures/equals.env" + expectedValues := map[string]string{ + "OPTION_A": "postgres://localhost:5432/database?sslmode=disable", + } + + loadEnvAndCompareValues(t, envFileName, expectedValues) +} + func TestLoadQuotedEnv(t *testing.T) { envFileName := "fixtures/quoted.env" expectedValues := map[string]string{