diff options
author | WeidiDeng <[email protected]> | 2023-10-13 14:28:20 +0800 |
---|---|---|
committer | GitHub <[email protected]> | 2023-10-13 02:28:20 -0400 |
commit | 1f60328e1740143f76bdee598281ebce8c4c8e3f (patch) | |
tree | 8409927dcac23d32129bdf533662174c005f4412 /caddyconfig | |
parent | 0e204b730aa2b1fa0835336b1117eff8c420f713 (diff) | |
download | caddy-1f60328e1740143f76bdee598281ebce8c4c8e3f.tar.gz caddy-1f60328e1740143f76bdee598281ebce8c4c8e3f.zip |
caddyfile: Fix variadic placeholder false positive when token contains `:` (#5883)
Diffstat (limited to 'caddyconfig')
-rw-r--r-- | caddyconfig/caddyfile/importargs.go | 7 | ||||
-rw-r--r-- | caddyconfig/caddyfile/parse_test.go | 4 |
2 files changed, 11 insertions, 0 deletions
diff --git a/caddyconfig/caddyfile/importargs.go b/caddyconfig/caddyfile/importargs.go index 2e21a3652..b2eb3e834 100644 --- a/caddyconfig/caddyfile/importargs.go +++ b/caddyconfig/caddyfile/importargs.go @@ -52,6 +52,13 @@ func parseVariadic(token Token, argCount int) (bool, int, int) { return false, 0, 0 } + // A valid token may contain several placeholders, and + // they may be separated by ":". It's not variadic. + // https://github.com/caddyserver/caddy/issues/5716 + if strings.Contains(start, "}") || strings.Contains(end, "{") { + return false, 0, 0 + } + var ( startIndex = 0 endIndex = argCount diff --git a/caddyconfig/caddyfile/parse_test.go b/caddyconfig/caddyfile/parse_test.go index b1104edf9..b270f1613 100644 --- a/caddyconfig/caddyfile/parse_test.go +++ b/caddyconfig/caddyfile/parse_test.go @@ -91,6 +91,10 @@ func TestParseVariadic(t *testing.T) { input: "{args[0:10]}", result: true, }, + { + input: "{args[0]}:{args[1]}:{args[2]}", + result: false, + }, } { token := Token{ File: "test", |