Reject new lines in keys
This commit is contained in:
@@ -254,9 +254,11 @@ func (l *tomlLexer) lexComma() tomlLexStateFn {
|
|||||||
func (l *tomlLexer) lexKey() tomlLexStateFn {
|
func (l *tomlLexer) lexKey() tomlLexStateFn {
|
||||||
l.ignore()
|
l.ignore()
|
||||||
inQuotes := false
|
inQuotes := false
|
||||||
for r := l.next(); isKeyChar(r); r = l.next() {
|
for r := l.next(); isKeyChar(r) || r == '\n'; r = l.next() {
|
||||||
if r == '"' {
|
if r == '"' {
|
||||||
inQuotes = !inQuotes
|
inQuotes = !inQuotes
|
||||||
|
} else if r == '\n' {
|
||||||
|
return l.errorf("keys cannot contain new lines")
|
||||||
} else if isSpace(r) && !inQuotes {
|
} else if isSpace(r) && !inQuotes {
|
||||||
break
|
break
|
||||||
} else if !isValidBareChar(r) && !inQuotes {
|
} else if !isValidBareChar(r) && !inQuotes {
|
||||||
|
|||||||
@@ -555,3 +555,9 @@ func TestQuotedKey(t *testing.T) {
|
|||||||
token{Position{1, 11}, tokenEOF, ""},
|
token{Position{1, 11}, tokenEOF, ""},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestKeyNewline(t *testing.T) {
|
||||||
|
testFlow(t, "a\n= 4", []token{
|
||||||
|
token{Position{1, 1}, tokenError, "keys cannot contain new lines"},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user