Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support = within double-quoted strings #9

Merged
merged 1 commit into from Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 8 additions & 14 deletions gotenv.go
Expand Up @@ -181,7 +181,7 @@ func parseLine(s string, env Env) error {
}

val = rv.ReplaceAllStringFunc(val, fv)
val = parseVal(val, env)
val = parseVal(val, env, hdq)

env[key] = val
return nil
Expand Down Expand Up @@ -242,21 +242,15 @@ func checkFormat(s string, env Env) error {
return fmt.Errorf("line `%s` doesn't match format", s)
}

func parseVal(val string, env Env) string {
if strings.Contains(val, "=") {
if !(val == "\n" || val == "\r") {
kv := strings.Split(val, "\n")
func parseVal(val string, env Env, ignoreNewlines bool) string {
if strings.Contains(val, "=") && !ignoreNewlines {
kv := strings.Split(val, "\r")

if len(kv) == 1 {
kv = strings.Split(val, "\r")
}

if len(kv) > 1 {
val = kv[0]
if len(kv) > 1 {
val = kv[0]

for i := 1; i < len(kv); i++ {
parseLine(kv[i], env)
}
for i := 1; i < len(kv); i++ {
parseLine(kv[i], env)
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions gotenv_test.go
Expand Up @@ -127,6 +127,9 @@ var formats = []struct {

// allows # in quoted value with spaces after separator
{`foo= "bar#baz" # comment`, gotenv.Env{"foo": "bar#baz"}, false},

// allows = in double quoted values with newlines (typically base64 padding)
{`foo="---\na==\n---"`, gotenv.Env{"foo": "---\na==\n---"}, false},
}

var errorFormats = []struct {
Expand Down