Reject new lines in keys
This commit is contained in:
@@ -254,9 +254,11 @@ func (l *tomlLexer) lexComma() tomlLexStateFn {
|
||||
func (l *tomlLexer) lexKey() tomlLexStateFn {
|
||||
l.ignore()
|
||||
inQuotes := false
|
||||
for r := l.next(); isKeyChar(r); r = l.next() {
|
||||
for r := l.next(); isKeyChar(r) || r == '\n'; r = l.next() {
|
||||
if r == '"' {
|
||||
inQuotes = !inQuotes
|
||||
} else if r == '\n' {
|
||||
return l.errorf("keys cannot contain new lines")
|
||||
} else if isSpace(r) && !inQuotes {
|
||||
break
|
||||
} else if !isValidBareChar(r) && !inQuotes {
|
||||
|
||||
@@ -555,3 +555,9 @@ func TestQuotedKey(t *testing.T) {
|
||||
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