toml: check for single-key reassignment in inline tables (#12436)

pull/12441/head
Larpon 2021-11-11 13:57:11 +01:00 committed by GitHub
parent 35f00c9f91
commit c8cb1bf6b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -497,8 +497,13 @@ pub fn (mut p Parser) inline_table(mut tbl map[string]ast.Value) ? {
} else {
p.ignore_while(parser.space_formatting)
key, val := p.key_value() ?
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'inserting @5 "$key.str()" = $val.to_json() into ${ptr_str(tbl)}')
tbl[key.str()] = val
key_str := key.str()
if _ := tbl[key_str] {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' key "$key_str" is already initialized with a value. At "$p.tok.kind" "$p.tok.lit" in this (excerpt): "...${p.excerpt()}..."')
}
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'inserting @5 "$key_str" = $val.to_json() into ${ptr_str(tbl)}')
tbl[key_str] = val
}
previous_token_was_value = true
}

View File

@ -19,8 +19,6 @@ const (
'table/injection-2.toml',
'table/injection-1.toml',
'table/duplicate-table-array.toml',
// Inline-table
'inline-table/duplicate-key.toml',
// Array
'array/tables-1.toml',
]