toml: disallow multiline keys (#12381)

pull/12387/head
Larpon 2021-11-04 13:26:25 +01:00 committed by GitHub
parent 59e21c2068
commit fc7f4c5b1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View File

@ -762,9 +762,7 @@ pub fn (mut p Parser) key() ?ast.Key {
ast.Key(p.quoted()) ast.Key(p.quoted())
} }
else { else {
error(@MOD + '.' + @STRUCT + '.' + @FN + ast.Key(ast.Null{})
' key expected .bare, .number, .quoted or .boolean but got "$p.tok.kind"')
ast.Key(ast.Bare{}) // TODO workaround bug
} }
} }
} }
@ -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') // panic(@MOD + '.' + @STRUCT + '.' + @FN + ' could not parse ${p.tok.kind} ("${p.tok.lit}") token \n$p.tok')
// return ast.Key(ast.Bare{}) // 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 return key
} }

View File

@ -42,7 +42,6 @@ const (
'key/without-value-2.toml', 'key/without-value-2.toml',
'key/no-eol.toml', 'key/no-eol.toml',
'key/after-array.toml', 'key/after-array.toml',
'key/multiline.toml',
] ]
) )