@marcel91200 / caddy Mirror · read-only / commits / b82db994
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

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

Francis Lavoie committed May 12, 2021 at 18:18 UTC b82db994f39c6991d673a7ae9836f5454b1f9668
2 files changed +9
caddyconfig/caddyfile/parse.go
+5
@@ -214,6 +214,11 @@ func (p *parser) addresses() error {
214 break
215 }
216
217 + // Users commonly forget to place a space between the address and the '{'
218 + if strings.HasSuffix(tkn, "{") {
219 + return p.Errf("Site addresses cannot end with a curly brace: '%s' - put a space between the token and the brace", tkn)
220 + }
221 +
222 if tkn != "" { // empty token possible if user typed ""
223 // Trailing comma indicates another address will follow, which
224 // may possibly be on the next line
caddyconfig/caddyfile/parse_test.go
+4
@@ -160,6 +160,10 @@ func TestParseOneAndImport(t *testing.T) {
160 "localhost",
161 }, []int{}},
162
163 + {`localhost{
164 + dir1
165 + }`, true, []string{}, []int{}},
166 +
167 {`localhost
168 dir1 {
169 nested {