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

Commit 170ae7d

Browse files
authored
Merge pull request #10 from ulyssessouza/add-multiline-tests
2 parents 8655247 + 76871d1 commit 170ae7d

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

fixtures/quoted.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ OPTION_F="2"
77
OPTION_G=""
88
OPTION_H="\n"
99
OPTION_I = "echo 'asd'"
10+
OPTION_J = 'first line
11+
second line
12+
third line
13+
and so on'
14+
OPTION_Z = "last value"

godotenv.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,12 @@ func parseLineWithLookup(line string, envMap map[string]string, lookupFn LookupF
266266
firstColon := strings.Index(line, ":")
267267
splitString := strings.SplitN(line, "=", 2)
268268
if firstColon != -1 && (firstColon < firstEquals || firstEquals == -1) {
269-
//this is a yaml-style line
269+
// This is a yaml-style line
270270
splitString = strings.SplitN(line, ":", 2)
271271
}
272272

273273
if len(splitString) != 2 {
274-
err = errors.New("Can't separate key from value")
274+
err = errors.New("can't separate key from value")
275275
return
276276
}
277277
key = exportRegex.ReplaceAllString(splitString[0], "$1")
@@ -341,15 +341,15 @@ func expandVariables(v string, envMap map[string]string, lookupFn LookupFn) stri
341341
if submatch[1] == "\\" || submatch[2] == "(" {
342342
return submatch[0][1:]
343343
} else if submatch[4] != "" {
344-
//first check if we have defined this already earlier
344+
// first check if we have defined this already earlier
345345
if envMap[submatch[4]] != "" {
346346
return envMap[submatch[4]]
347347
}
348348
if lookupFn == nil {
349349
return ""
350350
}
351-
//if we have not defined it, check the lookup function provided
352-
//by the user
351+
// if we have not defined it, check the lookup function provided
352+
// by the user
353353
s2, ok := lookupFn(submatch[4])
354354
if ok {
355355
return s2

godotenv_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ func TestLoadQuotedEnv(t *testing.T) {
189189
"OPTION_G": "",
190190
"OPTION_H": "\n",
191191
"OPTION_I": "echo 'asd'",
192+
"OPTION_J": `first line
193+
second line
194+
third line
195+
and so on`,
196+
"OPTION_Z": "last value",
192197
}
193198

194199
loadEnvAndCompareValues(t, Load, envFileName, expectedValues, noopPresets)

0 commit comments

Comments
 (0)