diff --git a/caddyfile/parse.go b/caddyfile/parse.go index abc64e682..54f7866ce 100644 --- a/caddyfile/parse.go +++ b/caddyfile/parse.go @@ -343,7 +343,7 @@ func (p *parser) doSingleImport(importFile string) ([]Token, error) { // are loaded into the current server block for later use // by directive setup functions. func (p *parser) directive() error { - dir := p.Val() + dir := replaceEnvVars(p.Val()) nesting := 0 // TODO: More helpful error message ("did you mean..." or "maybe you need to install its server type") diff --git a/caddyfile/parse_test.go b/caddyfile/parse_test.go index b81b4b322..a50507535 100644 --- a/caddyfile/parse_test.go +++ b/caddyfile/parse_test.go @@ -452,6 +452,7 @@ func TestEnvironmentReplacement(t *testing.T) { os.Setenv("PORT", "8080") os.Setenv("ADDRESS", "servername.com") os.Setenv("FOOBAR", "foobar") + os.Setenv("PARTIAL_DIR", "r1") // basic test; unix-style env vars p := testParser(`{$ADDRESS}`) @@ -460,6 +461,13 @@ func TestEnvironmentReplacement(t *testing.T) { t.Errorf("Expected key to be '%s' but was '%s'", expected, actual) } + // basic test; unix-style env vars + p = testParser(`di{$PARTIAL_DIR}`) + blocks, _ = p.parseAll() + if actual, expected := blocks[0].Keys[0], "dir1"; expected != actual { + t.Errorf("Expected key to be '%s' but was '%s'", expected, actual) + } + // multiple vars per token p = testParser(`{$ADDRESS}:{$PORT}`) blocks, _ = p.parseAll()