Commit f46da403 authored by Billie Cleek's avatar Billie Cleek Committed by Matt Holt

caddyfile: fix env var expansion after Go template (#2304)

parent 1f8d1df4
...@@ -424,7 +424,12 @@ func replaceEnvVars(s string) string { ...@@ -424,7 +424,12 @@ func replaceEnvVars(s string) string {
func replaceEnvReferences(s, refStart, refEnd string) string { func replaceEnvReferences(s, refStart, refEnd string) string {
index := strings.Index(s, refStart) index := strings.Index(s, refStart)
for index != -1 { for index != -1 {
endIndex := strings.Index(s, refEnd) endIndex := strings.Index(s[index:], refEnd)
if endIndex == -1 {
break
}
endIndex += index
if endIndex > index+len(refStart) { if endIndex > index+len(refStart) {
ref := s[index : endIndex+len(refEnd)] ref := s[index : endIndex+len(refEnd)]
s = strings.Replace(s, ref, os.Getenv(ref[len(refStart):len(ref)-len(refEnd)]), -1) s = strings.Replace(s, ref, os.Getenv(ref[len(refStart):len(ref)-len(refEnd)]), -1)
......
...@@ -526,6 +526,13 @@ func TestEnvironmentReplacement(t *testing.T) { ...@@ -526,6 +526,13 @@ func TestEnvironmentReplacement(t *testing.T) {
if actual, expected := blocks[0].Tokens["dir1"][1].Text, "Test foobar test"; expected != actual { if actual, expected := blocks[0].Tokens["dir1"][1].Text, "Test foobar test"; expected != actual {
t.Errorf("Expected argument to be '%s' but was '%s'", expected, actual) t.Errorf("Expected argument to be '%s' but was '%s'", expected, actual)
} }
// after end token
p = testParser(":1234\nanswer \"{{ .Name }} {$FOOBAR}\"")
blocks, _ = p.parseAll()
if actual, expected := blocks[0].Tokens["answer"][1].Text, "{{ .Name }} foobar"; expected != actual {
t.Errorf("Expected argument to be '%s' but was '%s'", expected, actual)
}
} }
func testParser(input string) parser { func testParser(input string) parser {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment