Raise error if regexp and template are not specified together (#2884)
Signed-off-by: Xiao An <hac@zju.edu.cn>
This commit is contained in:
parent
481dea50ad
commit
c1d7c2e69b
2 changed files with 11 additions and 4 deletions
|
@ -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())
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue