diff --git a/vlib/toml/parser/parser.v b/vlib/toml/parser/parser.v index be3cffebf2..0d858c812e 100644 --- a/vlib/toml/parser/parser.v +++ b/vlib/toml/parser/parser.v @@ -762,9 +762,7 @@ pub fn (mut p Parser) key() ?ast.Key { ast.Key(p.quoted()) } else { - error(@MOD + '.' + @STRUCT + '.' + @FN + - ' key expected .bare, .number, .quoted or .boolean but got "$p.tok.kind"') - ast.Key(ast.Bare{}) // TODO workaround bug + ast.Key(ast.Null{}) } } } @@ -774,6 +772,24 @@ pub fn (mut p Parser) key() ?ast.Key { // panic(@MOD + '.' + @STRUCT + '.' + @FN + ' could not parse ${p.tok.kind} ("${p.tok.lit}") token \n$p.tok') // return ast.Key(ast.Bare{}) + if key is ast.Null { + return error(@MOD + '.' + @STRUCT + '.' + @FN + + ' key expected .bare, .number, .quoted or .boolean but got "$p.tok.kind"') + } + + // A small exception that can't easily be done via `checker` + // since the `is_multiline` information is lost when using the key.text as a + // V `map` key directly. + if p.config.run_checks { + if key is ast.Quoted { + quoted := key as ast.Quoted + if quoted.is_multiline { + return error(@MOD + '.' + @STRUCT + '.' + @FN + + ' multiline string as key is not allowed. (excerpt): "...${p.excerpt()}..."') + } + } + } + return key } diff --git a/vlib/toml/tests/burntsushi.toml-test_test.v b/vlib/toml/tests/burntsushi.toml-test_test.v index 92a6c3265a..609bea246b 100644 --- a/vlib/toml/tests/burntsushi.toml-test_test.v +++ b/vlib/toml/tests/burntsushi.toml-test_test.v @@ -42,7 +42,6 @@ const ( 'key/without-value-2.toml', 'key/no-eol.toml', 'key/after-array.toml', - 'key/multiline.toml', ] )