mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-25 09:40:13 +08:00
cmd: Support '
quotes in envfile parsing (#5437)
This commit is contained in:
parent
ff35ba9ec3
commit
205b142614
13
cmd/main.go
13
cmd/main.go
|
@ -374,18 +374,19 @@ func parseEnvFile(envInput io.Reader) (map[string]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// quoted value: support newlines
|
// quoted value: support newlines
|
||||||
if strings.HasPrefix(val, `"`) {
|
if strings.HasPrefix(val, `"`) || strings.HasPrefix(val, "'") {
|
||||||
for !(strings.HasSuffix(line, `"`) && !strings.HasSuffix(line, `\"`)) {
|
quote := string(val[0])
|
||||||
val = strings.ReplaceAll(val, `\"`, `"`)
|
for !(strings.HasSuffix(line, quote) && !strings.HasSuffix(line, `\`+quote)) {
|
||||||
|
val = strings.ReplaceAll(val, `\`+quote, quote)
|
||||||
if !scanner.Scan() {
|
if !scanner.Scan() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
lineNumber++
|
lineNumber++
|
||||||
line = strings.ReplaceAll(scanner.Text(), `\"`, `"`)
|
line = strings.ReplaceAll(scanner.Text(), `\`+quote, quote)
|
||||||
val += "\n" + line
|
val += "\n" + line
|
||||||
}
|
}
|
||||||
val = strings.TrimPrefix(val, `"`)
|
val = strings.TrimPrefix(val, quote)
|
||||||
val = strings.TrimSuffix(val, `"`)
|
val = strings.TrimSuffix(val, quote)
|
||||||
}
|
}
|
||||||
|
|
||||||
envMap[key] = val
|
envMap[key] = val
|
||||||
|
|
Loading…
Reference in New Issue
Block a user