mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-27 06:03:48 +03:00
caddyfile: Fix comma edgecase in address parsing (#6616)
This commit is contained in:
parent
c8a76d003f
commit
ef4e0224a8
2 changed files with 13 additions and 4 deletions
|
@ -264,9 +264,14 @@ func (p *parser) addresses() error {
|
||||||
return p.Errf("Site addresses cannot contain a comma ',': '%s' - put a space after the comma to separate site addresses", value)
|
return p.Errf("Site addresses cannot contain a comma ',': '%s' - put a space after the comma to separate site addresses", value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// After the above, a comma surrounded by spaces would result
|
||||||
|
// in an empty token which we should ignore
|
||||||
|
if value != "" {
|
||||||
|
// Add the token as a site address
|
||||||
token.Text = value
|
token.Text = value
|
||||||
p.block.Keys = append(p.block.Keys, token)
|
p.block.Keys = append(p.block.Keys, token)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Advance token and possibly break out of loop or return error
|
// Advance token and possibly break out of loop or return error
|
||||||
hasNext := p.Next()
|
hasNext := p.Next()
|
||||||
|
|
|
@ -555,6 +555,10 @@ func TestParseAll(t *testing.T) {
|
||||||
{"localhost:1234", "http://host2"},
|
{"localhost:1234", "http://host2"},
|
||||||
}},
|
}},
|
||||||
|
|
||||||
|
{`foo.example.com , example.com`, false, [][]string{
|
||||||
|
{"foo.example.com", "example.com"},
|
||||||
|
}},
|
||||||
|
|
||||||
{`localhost:1234, http://host2,`, true, [][]string{}},
|
{`localhost:1234, http://host2,`, true, [][]string{}},
|
||||||
|
|
||||||
{`http://host1.com, http://host2.com {
|
{`http://host1.com, http://host2.com {
|
||||||
|
@ -614,8 +618,8 @@ func TestParseAll(t *testing.T) {
|
||||||
}
|
}
|
||||||
for j, block := range blocks {
|
for j, block := range blocks {
|
||||||
if len(block.Keys) != len(test.keys[j]) {
|
if len(block.Keys) != len(test.keys[j]) {
|
||||||
t.Errorf("Test %d: Expected %d keys in block %d, got %d",
|
t.Errorf("Test %d: Expected %d keys in block %d, got %d: %v",
|
||||||
i, len(test.keys[j]), j, len(block.Keys))
|
i, len(test.keys[j]), j, len(block.Keys), block.Keys)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for k, addr := range block.GetKeysText() {
|
for k, addr := range block.GetKeysText() {
|
||||||
|
|
Loading…
Reference in a new issue