Commit c1d7c2e6 authored by An Xiao's avatar An Xiao Committed by Miek Gieben

Raise error if regexp and template are not specified together (#2884)

Signed-off-by: default avatarXiao An <hac@zju.edu.cn>
parent 481dea50
...@@ -120,7 +120,7 @@ func autoParse(c *caddy.Controller) (Auto, error) { ...@@ -120,7 +120,7 @@ func autoParse(c *caddy.Controller) (Auto, error) {
} }
} }
// regexp // regexp template
if c.NextArg() { if c.NextArg() {
a.loader.re, err = regexp.Compile(c.Val()) a.loader.re, err = regexp.Compile(c.Val())
if err != nil { if err != nil {
...@@ -129,10 +129,10 @@ func autoParse(c *caddy.Controller) (Auto, error) { ...@@ -129,10 +129,10 @@ func autoParse(c *caddy.Controller) (Auto, error) {
if a.loader.re.NumSubexp() == 0 { if a.loader.re.NumSubexp() == 0 {
return a, c.Errf("Need at least one sub expression") 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()) a.loader.template = rewriteToExpand(c.Val())
} }
......
...@@ -75,6 +75,13 @@ func TestAutoParse(t *testing.T) { ...@@ -75,6 +75,13 @@ func TestAutoParse(t *testing.T) {
}`, }`,
true, "/tmp", "bliep", `(.*)`, 10 * time.Second, nil, true, "/tmp", "bliep", `(.*)`, 10 * time.Second, nil,
}, },
// no template specified.
{
`auto {
directory /tmp (.*)
}`,
true, "/tmp", "", `(.*)`, 60 * time.Second, nil,
},
// no directory specified. // no directory specified.
{ {
`auto example.org { `auto example.org {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment