summaryrefslogtreecommitdiffhomepage
path: root/caddyconfig
diff options
context:
space:
mode:
authorFrancis Lavoie <[email protected]>2021-05-12 18:18:44 -0400
committerGitHub <[email protected]>2021-05-12 16:18:44 -0600
commitb82db994f39c6991d673a7ae9836f5454b1f9668 (patch)
tree905452da2039e68eea404547f52377a1f5b05fcb /caddyconfig
parentaef8d4decceba3371d6722a81e17cd5f94162116 (diff)
downloadcaddy-b82db994f39c6991d673a7ae9836f5454b1f9668.tar.gz
caddy-b82db994f39c6991d673a7ae9836f5454b1f9668.zip
caddyfile: Add parse error on site address with trailing `{` (#4163)
* caddyfile: Add parse error on site address in `{` This is an incredibly common mistake made by users, so we should catch it earlier in the parser and give a more friendly message. Often it ends up adapting but with mistakes, or erroring out later due to other site addresses being read as directives. There's not really ever a situation where a lone '{' is valid at the end of a site address (but I suppose there are edgecases where the user wants to use a path matcher where it ends specifically in `{`, but... why?), so this should be fine. * Update caddyconfig/caddyfile/parse.go
Diffstat (limited to 'caddyconfig')
-rwxr-xr-xcaddyconfig/caddyfile/parse.go5
-rwxr-xr-xcaddyconfig/caddyfile/parse_test.go4
2 files changed, 9 insertions, 0 deletions
diff --git a/caddyconfig/caddyfile/parse.go b/caddyconfig/caddyfile/parse.go
index 96491bb30..d8707658e 100755
--- a/caddyconfig/caddyfile/parse.go
+++ b/caddyconfig/caddyfile/parse.go
@@ -214,6 +214,11 @@ func (p *parser) addresses() error {
break
}
+ // Users commonly forget to place a space between the address and the '{'
+ if strings.HasSuffix(tkn, "{") {
+ return p.Errf("Site addresses cannot end with a curly brace: '%s' - put a space between the token and the brace", tkn)
+ }
+
if tkn != "" { // empty token possible if user typed ""
// Trailing comma indicates another address will follow, which
// may possibly be on the next line
diff --git a/caddyconfig/caddyfile/parse_test.go b/caddyconfig/caddyfile/parse_test.go
index 3c7db79bd..12c713957 100755
--- a/caddyconfig/caddyfile/parse_test.go
+++ b/caddyconfig/caddyfile/parse_test.go
@@ -160,6 +160,10 @@ func TestParseOneAndImport(t *testing.T) {
"localhost",
}, []int{}},
+ {`localhost{
+ dir1
+ }`, true, []string{}, []int{}},
+
{`localhost
dir1 {
nested {