Skip to content

Commit c8cb1bf

Browse files
authored
toml: check for single-key reassignment in inline tables (#12436)
1 parent 35f00c9 commit c8cb1bf

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

vlib/toml/parser/parser.v

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,13 @@ pub fn (mut p Parser) inline_table(mut tbl map[string]ast.Value) ? {
497497
} else {
498498
p.ignore_while(parser.space_formatting)
499499
key, val := p.key_value() ?
500-
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'inserting @5 "$key.str()" = $val.to_json() into ${ptr_str(tbl)}')
501-
tbl[key.str()] = val
500+
key_str := key.str()
501+
if _ := tbl[key_str] {
502+
return error(@MOD + '.' + @STRUCT + '.' + @FN +
503+
' key "$key_str" is already initialized with a value. At "$p.tok.kind" "$p.tok.lit" in this (excerpt): "...${p.excerpt()}..."')
504+
}
505+
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'inserting @5 "$key_str" = $val.to_json() into ${ptr_str(tbl)}')
506+
tbl[key_str] = val
502507
}
503508
previous_token_was_value = true
504509
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ const (
1919
'table/injection-2.toml',
2020
'table/injection-1.toml',
2121
'table/duplicate-table-array.toml',
22-
// Inline-table
23-
'inline-table/duplicate-key.toml',
2422
// Array
2523
'array/tables-1.toml',
2624
]

0 commit comments

Comments
 (0)