mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-28 14:43:48 +03:00
caddyfile: Allow partial directive env var expansion (#2253)
This commit is contained in:
parent
dd83687447
commit
1f8d1df4ec
2 changed files with 9 additions and 1 deletions
|
@ -343,7 +343,7 @@ func (p *parser) doSingleImport(importFile string) ([]Token, error) {
|
||||||
// are loaded into the current server block for later use
|
// are loaded into the current server block for later use
|
||||||
// by directive setup functions.
|
// by directive setup functions.
|
||||||
func (p *parser) directive() error {
|
func (p *parser) directive() error {
|
||||||
dir := p.Val()
|
dir := replaceEnvVars(p.Val())
|
||||||
nesting := 0
|
nesting := 0
|
||||||
|
|
||||||
// TODO: More helpful error message ("did you mean..." or "maybe you need to install its server type")
|
// TODO: More helpful error message ("did you mean..." or "maybe you need to install its server type")
|
||||||
|
|
|
@ -452,6 +452,7 @@ func TestEnvironmentReplacement(t *testing.T) {
|
||||||
os.Setenv("PORT", "8080")
|
os.Setenv("PORT", "8080")
|
||||||
os.Setenv("ADDRESS", "servername.com")
|
os.Setenv("ADDRESS", "servername.com")
|
||||||
os.Setenv("FOOBAR", "foobar")
|
os.Setenv("FOOBAR", "foobar")
|
||||||
|
os.Setenv("PARTIAL_DIR", "r1")
|
||||||
|
|
||||||
// basic test; unix-style env vars
|
// basic test; unix-style env vars
|
||||||
p := testParser(`{$ADDRESS}`)
|
p := testParser(`{$ADDRESS}`)
|
||||||
|
@ -460,6 +461,13 @@ func TestEnvironmentReplacement(t *testing.T) {
|
||||||
t.Errorf("Expected key to be '%s' but was '%s'", expected, actual)
|
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
|
// multiple vars per token
|
||||||
p = testParser(`{$ADDRESS}:{$PORT}`)
|
p = testParser(`{$ADDRESS}:{$PORT}`)
|
||||||
blocks, _ = p.parseAll()
|
blocks, _ = p.parseAll()
|
||||||
|
|
Loading…
Reference in a new issue