Reject new lines in keys

This commit is contained in:
Thomas Pelletier
2015-07-14 20:07:43 -07:00
parent 16a681db2a
commit 41a8959f14
2 changed files with 9 additions and 1 deletions
+3 -1
View File
@@ -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 {
+6
View File
@@ -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"},
})
}