From c3a441f6ecb8577f41b53dfee839d95e8501eca7 Mon Sep 17 00:00:00 2001 From: Waldemar Quevedo Date: Mon, 28 Jan 2019 17:20:03 -0800 Subject: [PATCH] Fix dangling bracket and parens eof bugs in config parser Signed-off-by: Waldemar Quevedo --- conf/lex.go | 4 ++++ conf/lex_test.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/conf/lex.go b/conf/lex.go index 96702fe3..f3050331 100644 --- a/conf/lex.go +++ b/conf/lex.go @@ -656,6 +656,8 @@ func lexMapKeyStart(lx *lexer) stateFn { case r == dqStringStart: lx.next() return lexSkip(lx, lexMapDubQuotedKey) + case r == eof: + return lx.errorf("Unexpected EOF processing map.") } lx.ignore() lx.next() @@ -898,6 +900,8 @@ func lexBlock(lx *lexer) stateFn { return lx.pop() } lx.backup() + case r == eof: + return lx.errorf("Unexpected EOF processing block.") } return lexBlock } diff --git a/conf/lex_test.go b/conf/lex_test.go index c03f9137..20dab248 100644 --- a/conf/lex_test.go +++ b/conf/lex_test.go @@ -1030,6 +1030,49 @@ func TestKeyDanglingSingleQuotedString(t *testing.T) { 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) { expectedItems := []item{ {itemKey, "foo", 1, 0},