mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
quoted strings should allow internal spaces
This commit is contained in:
18
conf/lex.go
18
conf/lex.go
@@ -328,7 +328,7 @@ func lexValue(lx *lexer) stateFn {
|
||||
return lexMapKeyStart
|
||||
case r == dqStringStart || r == sqStringStart:
|
||||
lx.ignore() // ignore the " or '
|
||||
return lexString
|
||||
return lexQuotedString
|
||||
case r == '-':
|
||||
return lexNumberStart
|
||||
case isDigit(r):
|
||||
@@ -553,6 +553,22 @@ func (lx *lexer) isBool() bool {
|
||||
return str == "true" || str == "false" || str == "TRUE" || str == "FALSE"
|
||||
}
|
||||
|
||||
// lexQuotedString consumes the inner contents of a string. It assumes that the
|
||||
// beginning '"' has already been consumed and ignored. It will not interpret any
|
||||
// internal contents.
|
||||
func lexQuotedString(lx *lexer) stateFn {
|
||||
r := lx.next()
|
||||
switch {
|
||||
case r == dqStringEnd || r == sqStringEnd:
|
||||
lx.backup()
|
||||
lx.emit(itemString)
|
||||
lx.next()
|
||||
lx.ignore()
|
||||
return lx.pop()
|
||||
}
|
||||
return lexQuotedString
|
||||
}
|
||||
|
||||
// lexString consumes the inner contents of a string. It assumes that the
|
||||
// beginning '"' has already been consumed and ignored.
|
||||
func lexString(lx *lexer) stateFn {
|
||||
|
||||
@@ -457,3 +457,29 @@ func TestSpecialCharsMapQuotedKeys(t *testing.T) {
|
||||
lx = lex("foo = {\"bar-1.2.3\" = { port:4242 }}")
|
||||
expect(t, lx, expectedItems)
|
||||
}
|
||||
|
||||
var mlnestedmap = `
|
||||
systems {
|
||||
allinone {
|
||||
description: "This is a description."
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
func TestDoubleNestedMapsNewLines(t *testing.T) {
|
||||
expectedItems := []item{
|
||||
{itemKey, "systems", 2},
|
||||
{itemMapStart, "", 2},
|
||||
{itemKey, "allinone", 3},
|
||||
{itemMapStart, "", 3},
|
||||
{itemKey, "description", 4},
|
||||
{itemString, "This is a description.", 4},
|
||||
{itemMapEnd, "", 5},
|
||||
{itemMapEnd, "", 6},
|
||||
{itemEOF, "", 7},
|
||||
}
|
||||
lx := lex(mlnestedmap)
|
||||
expect(t, lx, expectedItems)
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user