mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Fix conf parser hang on dangling quote
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
This commit is contained in:
24
conf/lex.go
24
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
|
||||
}
|
||||
|
||||
@@ -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},
|
||||
|
||||
Reference in New Issue
Block a user