mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Fix dangling bracket and parens eof bugs in config parser
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
This commit is contained in:
@@ -656,6 +656,8 @@ func lexMapKeyStart(lx *lexer) stateFn {
|
|||||||
case r == dqStringStart:
|
case r == dqStringStart:
|
||||||
lx.next()
|
lx.next()
|
||||||
return lexSkip(lx, lexMapDubQuotedKey)
|
return lexSkip(lx, lexMapDubQuotedKey)
|
||||||
|
case r == eof:
|
||||||
|
return lx.errorf("Unexpected EOF processing map.")
|
||||||
}
|
}
|
||||||
lx.ignore()
|
lx.ignore()
|
||||||
lx.next()
|
lx.next()
|
||||||
@@ -898,6 +900,8 @@ func lexBlock(lx *lexer) stateFn {
|
|||||||
return lx.pop()
|
return lx.pop()
|
||||||
}
|
}
|
||||||
lx.backup()
|
lx.backup()
|
||||||
|
case r == eof:
|
||||||
|
return lx.errorf("Unexpected EOF processing block.")
|
||||||
}
|
}
|
||||||
return lexBlock
|
return lexBlock
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1030,6 +1030,49 @@ func TestKeyDanglingSingleQuotedString(t *testing.T) {
|
|||||||
expect(t, lx, expectedItems)
|
expect(t, lx, expectedItems)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var mapdanglingbracket = `
|
||||||
|
listen = 4222
|
||||||
|
|
||||||
|
cluster = {
|
||||||
|
|
||||||
|
foo = bar
|
||||||
|
|
||||||
|
`
|
||||||
|
|
||||||
|
func TestMapDanglingBracket(t *testing.T) {
|
||||||
|
expectedItems := []item{
|
||||||
|
{itemKey, "listen", 2, 1},
|
||||||
|
{itemInteger, "4222", 2, 10},
|
||||||
|
{itemKey, "cluster", 4, 1},
|
||||||
|
{itemMapStart, "", 4, 12},
|
||||||
|
{itemKey, "foo", 6, 3},
|
||||||
|
{itemString, "bar", 6, 9},
|
||||||
|
{itemError, "Unexpected EOF processing map.", 8, 1},
|
||||||
|
}
|
||||||
|
lx := lex(mapdanglingbracket)
|
||||||
|
expect(t, lx, expectedItems)
|
||||||
|
}
|
||||||
|
|
||||||
|
var blockdanglingparens = `
|
||||||
|
listen = 4222
|
||||||
|
|
||||||
|
quote = (
|
||||||
|
|
||||||
|
foo = bar
|
||||||
|
|
||||||
|
`
|
||||||
|
|
||||||
|
func TestBlockDanglingParens(t *testing.T) {
|
||||||
|
expectedItems := []item{
|
||||||
|
{itemKey, "listen", 2, 1},
|
||||||
|
{itemInteger, "4222", 2, 10},
|
||||||
|
{itemKey, "quote", 4, 1},
|
||||||
|
{itemError, "Unexpected EOF processing block.", 8, 1},
|
||||||
|
}
|
||||||
|
lx := lex(blockdanglingparens)
|
||||||
|
expect(t, lx, expectedItems)
|
||||||
|
}
|
||||||
|
|
||||||
func TestMapQuotedKeys(t *testing.T) {
|
func TestMapQuotedKeys(t *testing.T) {
|
||||||
expectedItems := []item{
|
expectedItems := []item{
|
||||||
{itemKey, "foo", 1, 0},
|
{itemKey, "foo", 1, 0},
|
||||||
|
|||||||
Reference in New Issue
Block a user