From ae5e2d96b7a17f74a98b173102f922ec2bc65811 Mon Sep 17 00:00:00 2001 From: WeidiDeng Date: Fri, 13 Oct 2023 14:28:20 +0800 Subject: [PATCH] caddyfile: Fix variadic placeholder false positive when token contains `:` (#5883) --- caddyconfig/caddyfile/importargs.go | 7 +++++++ caddyconfig/caddyfile/parse_test.go | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/caddyconfig/caddyfile/importargs.go b/caddyconfig/caddyfile/importargs.go index 2e21a365..b2eb3e83 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 b1104edf..b270f161 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",