Reject new lines in keys
diff --git a/lexer.go b/lexer.go index f162565..7cb789b 100644 --- a/lexer.go +++ b/lexer.go
@@ -254,9 +254,11 @@ 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 {
diff --git a/lexer_test.go b/lexer_test.go index 6b18a57..d1cd130 100644 --- a/lexer_test.go +++ b/lexer_test.go
@@ -555,3 +555,9 @@ 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"}, + }) +}