@marcel91200 / caddy Mirror · read-only / commits / ef4e0224
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 12, 07:00 UTC

caddyfile: Fix comma edgecase in address parsing (#6616)

Francis Lavoie committed Oct 10, 2024 at 16:26 UTC ef4e0224a8495fc29847d865087febdee8736e3b
2 files changed +13 -4
caddyconfig/caddyfile/parse.go
+7 -2
@@ -264,8 +264,13 @@ func (p *parser) addresses() error {
264 return p.Errf("Site addresses cannot contain a comma ',': '%s' - put a space after the comma to separate site addresses", value)
265 }
266
267 - token.Text = value
268 - p.block.Keys = append(p.block.Keys, token)
267 + // After the above, a comma surrounded by spaces would result
268 + // in an empty token which we should ignore
269 + if value != "" {
270 + // Add the token as a site address
271 + token.Text = value
272 + p.block.Keys = append(p.block.Keys, token)
273 + }
274 }
275
276 // Advance token and possibly break out of loop or return error
caddyconfig/caddyfile/parse_test.go
+6 -2
@@ -555,6 +555,10 @@ func TestParseAll(t *testing.T) {
555 {"localhost:1234", "http://host2"},
556 }},
557
558 + {`foo.example.com , example.com`, false, [][]string{
559 + {"foo.example.com", "example.com"},
560 + }},
561 +
562 {`localhost:1234, http://host2,`, true, [][]string{}},
563
564 {`http://host1.com, http://host2.com {
@@ -614,8 +618,8 @@ func TestParseAll(t *testing.T) {
618 }
619 for j, block := range blocks {
620 if len(block.Keys) != len(test.keys[j]) {
617 - t.Errorf("Test %d: Expected %d keys in block %d, got %d",
618 - i, len(test.keys[j]), j, len(block.Keys))
621 + t.Errorf("Test %d: Expected %d keys in block %d, got %d: %v",
622 + i, len(test.keys[j]), j, len(block.Keys), block.Keys)
623 continue
624 }
625 for k, addr := range block.GetKeysText() {