forked from coop-cloud-mirrors/godotenv
Start trying to do comments/quoting properly.
This commit is contained in:
21
godotenv.go
21
godotenv.go
@ -76,8 +76,25 @@ func parseLine(line string) (key string, value string, err error) {
|
||||
}
|
||||
key = strings.Trim(key, " ")
|
||||
|
||||
value = strings.Trim(splitString[1], " \"'")
|
||||
value = strings.Replace(value, "\\\"", "\"", -1)
|
||||
value = splitString[1]
|
||||
|
||||
// ditch the comments
|
||||
if strings.Contains(value, "#") {
|
||||
value = strings.Trim(strings.Split(value, "#")[0], " ")
|
||||
}
|
||||
|
||||
// check if we've got quoted values
|
||||
if strings.Count(value, "\"") == 2 || strings.Count(value, "'") == 2 {
|
||||
// pull the quotes off the edge
|
||||
value = strings.Trim(value, "\"'")
|
||||
|
||||
// expand quotes
|
||||
value = strings.Replace(value, "\\\"", "\"", -1)
|
||||
// expand newlines
|
||||
value = strings.Replace(value, "\\n", "\n", -1)
|
||||
}
|
||||
// trim
|
||||
value = strings.Trim(value, " ")
|
||||
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user