Skip to content

Commit fc7f4c5

Browse files
authored
toml: disallow multiline keys (#12381)
1 parent 59e21c2 commit fc7f4c5

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

vlib/toml/parser/parser.v

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -762,9 +762,7 @@ pub fn (mut p Parser) key() ?ast.Key {
762762
ast.Key(p.quoted())
763763
}
764764
else {
765-
error(@MOD + '.' + @STRUCT + '.' + @FN +
766-
' key expected .bare, .number, .quoted or .boolean but got "$p.tok.kind"')
767-
ast.Key(ast.Bare{}) // TODO workaround bug
765+
ast.Key(ast.Null{})
768766
}
769767
}
770768
}
@@ -774,6 +772,24 @@ pub fn (mut p Parser) key() ?ast.Key {
774772
// panic(@MOD + '.' + @STRUCT + '.' + @FN + ' could not parse ${p.tok.kind} ("${p.tok.lit}") token \n$p.tok')
775773
// return ast.Key(ast.Bare{})
776774

775+
if key is ast.Null {
776+
return error(@MOD + '.' + @STRUCT + '.' + @FN +
777+
' key expected .bare, .number, .quoted or .boolean but got "$p.tok.kind"')
778+
}
779+
780+
// A small exception that can't easily be done via `checker`
781+
// since the `is_multiline` information is lost when using the key.text as a
782+
// V `map` key directly.
783+
if p.config.run_checks {
784+
if key is ast.Quoted {
785+
quoted := key as ast.Quoted
786+
if quoted.is_multiline {
787+
return error(@MOD + '.' + @STRUCT + '.' + @FN +
788+
' multiline string as key is not allowed. (excerpt): "...${p.excerpt()}..."')
789+
}
790+
}
791+
}
792+
777793
return key
778794
}
779795

vlib/toml/tests/burntsushi.toml-test_test.v

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ const (
4242
'key/without-value-2.toml',
4343
'key/no-eol.toml',
4444
'key/after-array.toml',
45-
'key/multiline.toml',
4645
]
4746
)
4847

0 commit comments

Comments
 (0)