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

Commit

Permalink
Merge pull request #10 from ulyssessouza/add-multiline-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ndeloof authored Nov 5, 2021
2 parents 8655247 + 76871d1 commit 170ae7d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions fixtures/quoted.env
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ OPTION_F="2"
OPTION_G=""
OPTION_H="\n"
OPTION_I = "echo 'asd'"
OPTION_J = 'first line
second line
third line
and so on'
OPTION_Z = "last value"
10 changes: 5 additions & 5 deletions godotenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,12 @@ func parseLineWithLookup(line string, envMap map[string]string, lookupFn LookupF
firstColon := strings.Index(line, ":")
splitString := strings.SplitN(line, "=", 2)
if firstColon != -1 && (firstColon < firstEquals || firstEquals == -1) {
//this is a yaml-style line
// This is a yaml-style line
splitString = strings.SplitN(line, ":", 2)
}

if len(splitString) != 2 {
err = errors.New("Can't separate key from value")
err = errors.New("can't separate key from value")
return
}
key = exportRegex.ReplaceAllString(splitString[0], "$1")
Expand Down Expand Up @@ -341,15 +341,15 @@ func expandVariables(v string, envMap map[string]string, lookupFn LookupFn) stri
if submatch[1] == "\\" || submatch[2] == "(" {
return submatch[0][1:]
} else if submatch[4] != "" {
//first check if we have defined this already earlier
// first check if we have defined this already earlier
if envMap[submatch[4]] != "" {
return envMap[submatch[4]]
}
if lookupFn == nil {
return ""
}
//if we have not defined it, check the lookup function provided
//by the user
// if we have not defined it, check the lookup function provided
// by the user
s2, ok := lookupFn(submatch[4])
if ok {
return s2
Expand Down
5 changes: 5 additions & 0 deletions godotenv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ func TestLoadQuotedEnv(t *testing.T) {
"OPTION_G": "",
"OPTION_H": "\n",
"OPTION_I": "echo 'asd'",
"OPTION_J": `first line
second line
third line
and so on`,
"OPTION_Z": "last value",
}

loadEnvAndCompareValues(t, Load, envFileName, expectedValues, noopPresets)
Expand Down

0 comments on commit 170ae7d

Please sign in to comment.