diff --git a/caddyconfig/caddyfile/parse.go b/caddyconfig/caddyfile/parse.go index 52abf478..96491bb3 100755 --- a/caddyconfig/caddyfile/parse.go +++ b/caddyconfig/caddyfile/parse.go @@ -321,7 +321,7 @@ func (p *parser) doImport() error { args := p.RemainingArgs() // add args to the replacer - repl := caddy.NewReplacer() + repl := caddy.NewEmptyReplacer() for index, arg := range args { repl.Set("args."+strconv.Itoa(index), arg) } diff --git a/caddytest/integration/caddyfile_adapt/import_args_snippet_env_placeholder.txt b/caddytest/integration/caddyfile_adapt/import_args_snippet_env_placeholder.txt new file mode 100644 index 00000000..1bc907e5 --- /dev/null +++ b/caddytest/integration/caddyfile_adapt/import_args_snippet_env_placeholder.txt @@ -0,0 +1,31 @@ +(foo) { + respond {env.FOO} +} + +:80 { + import foo +} +---------- +{ + "apps": { + "http": { + "servers": { + "srv0": { + "listen": [ + ":80" + ], + "routes": [ + { + "handle": [ + { + "body": "{env.FOO}", + "handler": "static_response" + } + ] + } + ] + } + } + } + } +} \ No newline at end of file diff --git a/replacer.go b/replacer.go index 29d8e26a..e6cfdede 100644 --- a/replacer.go +++ b/replacer.go @@ -36,6 +36,18 @@ func NewReplacer() *Replacer { return rep } +// NewEmptyReplacer returns a new Replacer, +// without the global default replacements. +func NewEmptyReplacer() *Replacer { + rep := &Replacer{ + static: make(map[string]interface{}), + } + rep.providers = []ReplacerFunc{ + rep.fromStatic, + } + return rep +} + // Replacer can replace values in strings. // A default/empty Replacer is not valid; // use NewReplacer to make one.