forked from coop-cloud-mirrors/godotenv
Merge pull request #27 from goenning/empty_var
allow usage of empty var on .env
This commit is contained in:
commit
eaf676fc03
@ -3,3 +3,5 @@ OPTION_B=2
|
|||||||
OPTION_C= 3
|
OPTION_C= 3
|
||||||
OPTION_D =4
|
OPTION_D =4
|
||||||
OPTION_E = 5
|
OPTION_E = 5
|
||||||
|
OPTION_F =
|
||||||
|
OPTION_G=
|
21
godotenv.go
21
godotenv.go
@ -212,20 +212,23 @@ func parseLine(line string) (key string, value string, err error) {
|
|||||||
|
|
||||||
// Parse the value
|
// Parse the value
|
||||||
value = splitString[1]
|
value = splitString[1]
|
||||||
|
|
||||||
// trim
|
// trim
|
||||||
value = strings.Trim(value, " ")
|
value = strings.Trim(value, " ")
|
||||||
|
|
||||||
// check if we've got quoted values
|
// check if we've got quoted values
|
||||||
first := string(value[0:1])
|
if value != "" {
|
||||||
last := string(value[len(value)-1:])
|
first := string(value[0:1])
|
||||||
if first == last && strings.ContainsAny(first, `"'`) {
|
last := string(value[len(value)-1:])
|
||||||
// pull the quotes off the edges
|
if first == last && strings.ContainsAny(first, `"'`) {
|
||||||
value = strings.Trim(value, `"'`)
|
// pull the quotes off the edges
|
||||||
|
value = strings.Trim(value, `"'`)
|
||||||
|
|
||||||
// expand quotes
|
// expand quotes
|
||||||
value = strings.Replace(value, `\"`, `"`, -1)
|
value = strings.Replace(value, `\"`, `"`, -1)
|
||||||
// expand newlines
|
// expand newlines
|
||||||
value = strings.Replace(value, `\n`, "\n", -1)
|
value = strings.Replace(value, `\n`, "\n", -1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -74,6 +74,8 @@ func TestReadPlainEnv(t *testing.T) {
|
|||||||
"OPTION_C": "3",
|
"OPTION_C": "3",
|
||||||
"OPTION_D": "4",
|
"OPTION_D": "4",
|
||||||
"OPTION_E": "5",
|
"OPTION_E": "5",
|
||||||
|
"OPTION_F": "",
|
||||||
|
"OPTION_G": "",
|
||||||
}
|
}
|
||||||
|
|
||||||
envMap, err := Read(envFileName)
|
envMap, err := Read(envFileName)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user