diff --git a/conf/lex.go b/conf/lex.go index e6ce1ad4..96702fe3 100644 --- a/conf/lex.go +++ b/conf/lex.go @@ -346,6 +346,12 @@ func lexDubQuotedKey(lx *lexer) stateFn { lx.emit(itemKey) lx.next() return lexSkip(lx, lexKeyEnd) + } else if r == eof { + if lx.pos > lx.start { + return lx.errorf("Unexpected EOF.") + } + lx.emit(itemEOF) + return nil } lx.next() return lexDubQuotedKey @@ -358,6 +364,12 @@ func lexQuotedKey(lx *lexer) stateFn { lx.emit(itemKey) lx.next() return lexSkip(lx, lexKeyEnd) + } else if r == eof { + if lx.pos > lx.start { + return lx.errorf("Unexpected EOF.") + } + lx.emit(itemEOF) + return nil } lx.next() return lexQuotedKey @@ -788,6 +800,12 @@ func lexQuotedString(lx *lexer) stateFn { lx.next() lx.ignore() return lx.pop() + case r == eof: + if lx.pos > lx.start { + return lx.errorf("Unexpected EOF.") + } + lx.emit(itemEOF) + return nil } return lexQuotedString } @@ -807,6 +825,12 @@ func lexDubQuotedString(lx *lexer) stateFn { lx.next() lx.ignore() return lx.pop() + case r == eof: + if lx.pos > lx.start { + return lx.errorf("Unexpected EOF.") + } + lx.emit(itemEOF) + return nil } return lexDubQuotedString } diff --git a/conf/lex_test.go b/conf/lex_test.go index d9ce2f65..c03f9137 100644 --- a/conf/lex_test.go +++ b/conf/lex_test.go @@ -958,6 +958,78 @@ func TestNonQuotedStrings(t *testing.T) { expect(t, lx, expectedItems) } +var danglingquote = ` +listen: "localhost:4242 + +http: localhost:8222 +` + +func TestDanglingQuotedString(t *testing.T) { + expectedItems := []item{ + {itemKey, "listen", 2, 1}, + {itemError, "Unexpected EOF.", 5, 1}, + } + lx := lex(danglingquote) + expect(t, lx, expectedItems) +} + +var keydanglingquote = ` +foo = " +listen: " + +http: localhost:8222 + +" +` + +func TestKeyDanglingQuotedString(t *testing.T) { + expectedItems := []item{ + {itemKey, "foo", 2, 1}, + {itemString, "\nlisten: ", 3, 8}, + {itemKey, "http", 5, 1}, + {itemString, "localhost:8222", 5, 7}, + {itemError, "Unexpected EOF.", 8, 1}, + } + lx := lex(keydanglingquote) + expect(t, lx, expectedItems) +} + +var danglingsquote = ` +listen: 'localhost:4242 + +http: localhost:8222 +` + +func TestDanglingSingleQuotedString(t *testing.T) { + expectedItems := []item{ + {itemKey, "listen", 2, 1}, + {itemError, "Unexpected EOF.", 5, 1}, + } + lx := lex(danglingsquote) + expect(t, lx, expectedItems) +} + +var keydanglingsquote = ` +foo = ' +listen: ' + +http: localhost:8222 + +' +` + +func TestKeyDanglingSingleQuotedString(t *testing.T) { + expectedItems := []item{ + {itemKey, "foo", 2, 1}, + {itemString, "\nlisten: ", 3, 8}, + {itemKey, "http", 5, 1}, + {itemString, "localhost:8222", 5, 7}, + {itemError, "Unexpected EOF.", 8, 1}, + } + lx := lex(keydanglingsquote) + expect(t, lx, expectedItems) +} + func TestMapQuotedKeys(t *testing.T) { expectedItems := []item{ {itemKey, "foo", 1, 0},