summaryrefslogtreecommitdiff
path: root/caddyconfig/caddyfile/parse_test.go
diff options
context:
space:
mode:
authorWeidiDeng <weidi_deng@icloud.com>2023-08-05 00:44:38 +0800
committerGitHub <noreply@github.com>2023-08-04 10:44:38 -0600
commit9f34383c02f1691e54280285a6499893fcbbb4c7 (patch)
treebf87ea45cb4e66dae2b5689f4a72231351dd888a /caddyconfig/caddyfile/parse_test.go
parentb07b198764de738f3b473f416422eaf0619c654d (diff)
caddyfile: check that matched key is not a substring of the replacement key (#5685)
Diffstat (limited to 'caddyconfig/caddyfile/parse_test.go')
-rw-r--r--caddyconfig/caddyfile/parse_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/caddyconfig/caddyfile/parse_test.go b/caddyconfig/caddyfile/parse_test.go
index bbae785..b1104ed 100644
--- a/caddyconfig/caddyfile/parse_test.go
+++ b/caddyconfig/caddyfile/parse_test.go
@@ -718,6 +718,36 @@ func TestEnvironmentReplacement(t *testing.T) {
}
}
+func TestImportReplacementInJSONWithBrace(t *testing.T) {
+ for i, test := range []struct {
+ args []string
+ input string
+ expect string
+ }{
+ {
+ args: []string{"123"},
+ input: "{args[0]}",
+ expect: "123",
+ },
+ {
+ args: []string{"123"},
+ input: `{"key":"{args[0]}"}`,
+ expect: `{"key":"123"}`,
+ },
+ {
+ args: []string{"123", "123"},
+ input: `{"key":[{args[0]},{args[1]}]}`,
+ expect: `{"key":[123,123]}`,
+ },
+ } {
+ repl := makeArgsReplacer(test.args)
+ actual := repl.ReplaceKnown(test.input, "")
+ if actual != test.expect {
+ t.Errorf("Test %d: Expected: '%s' but got '%s'", i, test.expect, actual)
+ }
+ }
+}
+
func TestSnippets(t *testing.T) {
p := testParser(`
(common) {