forked from coop-cloud-mirrors/godotenv
rudimentry support for nested quotes
This commit is contained in:
parent
b9324c6f3c
commit
84bf91f40e
@ -234,7 +234,7 @@ func parseValue(value string) string {
|
|||||||
last := string(value[len(value)-1:])
|
last := string(value[len(value)-1:])
|
||||||
if first == last && strings.ContainsAny(first, `"'`) {
|
if first == last && strings.ContainsAny(first, `"'`) {
|
||||||
// pull the quotes off the edges
|
// pull the quotes off the edges
|
||||||
value = strings.Trim(value, `"'`)
|
value = value[1 : len(value)-1]
|
||||||
// handle escapes
|
// handle escapes
|
||||||
escapeRegex := regexp.MustCompile(`\\.`)
|
escapeRegex := regexp.MustCompile(`\\.`)
|
||||||
value = escapeRegex.ReplaceAllStringFunc(value, func(match string) string {
|
value = escapeRegex.ReplaceAllStringFunc(value, func(match string) string {
|
||||||
|
@ -199,6 +199,9 @@ func TestParsing(t *testing.T) {
|
|||||||
// parses escaped double quotes
|
// parses escaped double quotes
|
||||||
parseAndCompare(t, `FOO="escaped\"bar"`, "FOO", `escaped"bar`)
|
parseAndCompare(t, `FOO="escaped\"bar"`, "FOO", `escaped"bar`)
|
||||||
|
|
||||||
|
// parses single quotes inside double quotes
|
||||||
|
parseAndCompare(t, `FOO="'d'"`, "FOO", `'d'`)
|
||||||
|
|
||||||
// parses yaml style options
|
// parses yaml style options
|
||||||
parseAndCompare(t, "OPTION_A: 1", "OPTION_A", "1")
|
parseAndCompare(t, "OPTION_A: 1", "OPTION_A", "1")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user