From 6db3615547b8911ac81dc2b23c1ed8bedbef0fdb Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Tue, 16 Jun 2020 10:41:37 -0600 Subject: caddyhttp: Enable matching empty query string Caddyfile syntax: query "" Or a nil matcher in the JSON should also match an empty query string. See https://caddy.community/t/v2-match-empty-query/8708?u=matt --- modules/caddyhttp/matchers_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'modules/caddyhttp/matchers_test.go') diff --git a/modules/caddyhttp/matchers_test.go b/modules/caddyhttp/matchers_test.go index 9b3a9a8..219ada8 100644 --- a/modules/caddyhttp/matchers_test.go +++ b/modules/caddyhttp/matchers_test.go @@ -528,6 +528,24 @@ func TestQueryMatcher(t *testing.T) { input: "/?someparam", expect: false, }, + { + scenario: "nil matcher value should match empty query", + match: MatchQuery(nil), + input: "/?", + expect: true, + }, + { + scenario: "nil matcher value should NOT match a non-empty query", + match: MatchQuery(nil), + input: "/?foo=bar", + expect: false, + }, + { + scenario: "non-nil matcher should NOT match an empty query", + match: MatchQuery{"": []string{}}, + input: "/?", + expect: false, + }, } { u, _ := url.Parse(tc.input) -- cgit v1.2.3