diff options
author | WeidiDeng <weidi_deng@icloud.com> | 2023-05-23 05:36:55 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-22 15:36:55 -0600 |
commit | cee4441cb1d485b38d728168a315cda5641d84fb (patch) | |
tree | b024ba176895a72d31993e8c069626adfe46fac9 /caddyconfig/httpcaddyfile | |
parent | 5bd9c49042112183f0902a7ce6252aebf58e1ac9 (diff) |
caddyfile: Do not replace import tokens if they are part of a snippet (#5539)
* fix variadic placeholder in imported file which also imports
* fix tests.
* skip replacing args when imported token may be part of a snippet
Diffstat (limited to 'caddyconfig/httpcaddyfile')
4 files changed, 54 insertions, 0 deletions
diff --git a/caddyconfig/httpcaddyfile/builtins_test.go b/caddyconfig/httpcaddyfile/builtins_test.go index 6ae4b31..34b4124 100644 --- a/caddyconfig/httpcaddyfile/builtins_test.go +++ b/caddyconfig/httpcaddyfile/builtins_test.go @@ -243,6 +243,27 @@ func TestImportErrorLine(t *testing.T) { return err != nil && strings.Contains(err.Error(), "Caddyfile:5 (import t1):2") }, }, + { + input: ` + import testdata/import_variadic_snippet.txt + :8080 { + import t1 true + }`, + errorFunc: func(err error) bool { + return err == nil + }, + }, + { + input: ` + import testdata/import_variadic_with_import.txt + :8080 { + import t1 true + import t2 true + }`, + errorFunc: func(err error) bool { + return err == nil + }, + }, } { adapter := caddyfile.Adapter{ ServerType: ServerType{}, diff --git a/caddyconfig/httpcaddyfile/testdata/import_variadic.txt b/caddyconfig/httpcaddyfile/testdata/import_variadic.txt new file mode 100644 index 0000000..f1e50e0 --- /dev/null +++ b/caddyconfig/httpcaddyfile/testdata/import_variadic.txt @@ -0,0 +1,9 @@ +(t2) { + respond 200 { + body {args[:]} + } +} + +:8082 { + import t2 false +}
\ No newline at end of file diff --git a/caddyconfig/httpcaddyfile/testdata/import_variadic_snippet.txt b/caddyconfig/httpcaddyfile/testdata/import_variadic_snippet.txt new file mode 100644 index 0000000..a02fcf9 --- /dev/null +++ b/caddyconfig/httpcaddyfile/testdata/import_variadic_snippet.txt @@ -0,0 +1,9 @@ +(t1) { + respond 200 { + body {args[:]} + } +} + +:8081 { + import t1 false +}
\ No newline at end of file diff --git a/caddyconfig/httpcaddyfile/testdata/import_variadic_with_import.txt b/caddyconfig/httpcaddyfile/testdata/import_variadic_with_import.txt new file mode 100644 index 0000000..ab1b32d --- /dev/null +++ b/caddyconfig/httpcaddyfile/testdata/import_variadic_with_import.txt @@ -0,0 +1,15 @@ +(t1) { + respond 200 { + body {args[:]} + } +} + +:8081 { + import t1 false +} + +import import_variadic.txt + +:8083 { + import t2 true +}
\ No newline at end of file |