aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar An Xiao <hac@zju.edu.cn> 2019-06-13 19:07:41 +0800
committerGravatar Miek Gieben <miek@miek.nl> 2019-06-13 12:07:41 +0100
commitc1d7c2e69becba8c9dd700aea9819a4ebde2facb (patch)
treef6cd09fc12e0fb21505ffee9a698733adde1aa78
parent481dea50adf367dff57bbe0ed454ae6f5eaf72d7 (diff)
downloadcoredns-c1d7c2e69becba8c9dd700aea9819a4ebde2facb.tar.gz
coredns-c1d7c2e69becba8c9dd700aea9819a4ebde2facb.tar.zst
coredns-c1d7c2e69becba8c9dd700aea9819a4ebde2facb.zip
Raise error if regexp and template are not specified together (#2884)
Signed-off-by: Xiao An <hac@zju.edu.cn>
-rw-r--r--plugin/auto/setup.go8
-rw-r--r--plugin/auto/setup_test.go7
2 files changed, 11 insertions, 4 deletions
diff --git a/plugin/auto/setup.go b/plugin/auto/setup.go
index 2e2d0a37d..d6c4f8290 100644
--- a/plugin/auto/setup.go
+++ b/plugin/auto/setup.go
@@ -120,7 +120,7 @@ func autoParse(c *caddy.Controller) (Auto, error) {
}
}
- // regexp
+ // regexp template
if c.NextArg() {
a.loader.re, err = regexp.Compile(c.Val())
if err != nil {
@@ -129,10 +129,10 @@ func autoParse(c *caddy.Controller) (Auto, error) {
if a.loader.re.NumSubexp() == 0 {
return a, c.Errf("Need at least one sub expression")
}
- }
- // template
- if c.NextArg() {
+ if !c.NextArg() {
+ return a, c.ArgErr()
+ }
a.loader.template = rewriteToExpand(c.Val())
}
diff --git a/plugin/auto/setup_test.go b/plugin/auto/setup_test.go
index 3ea50eb99..e3c59d673 100644
--- a/plugin/auto/setup_test.go
+++ b/plugin/auto/setup_test.go
@@ -75,6 +75,13 @@ func TestAutoParse(t *testing.T) {
}`,
true, "/tmp", "bliep", `(.*)`, 10 * time.Second, nil,
},
+ // no template specified.
+ {
+ `auto {
+ directory /tmp (.*)
+ }`,
+ true, "/tmp", "", `(.*)`, 60 * time.Second, nil,
+ },
// no directory specified.
{
`auto example.org {