From 31b787a8970f42bddc15aa32cdd4f9101d49e92e Mon Sep 17 00:00:00 2001 From: lmp Date: Sat, 27 Dec 2025 16:52:52 +0100 Subject: [PATCH] toml: fix invalid exception by erroring on duplicate keys in inline table --- vlib/toml/parser/parser.v | 11 ++++++++--- vlib/toml/tests/toml_lang_test.v | 1 - 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/vlib/toml/parser/parser.v b/vlib/toml/parser/parser.v index 83605f758dfb15..fbf0a3e049a075 100644 --- a/vlib/toml/parser/parser.v +++ b/vlib/toml/parser/parser.v @@ -818,19 +818,24 @@ pub fn (mut p Parser) inline_table(mut tbl map[string]ast.Value) ! { p.check_immutable(left_most)! } } + key_str := key.str() + util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'inserting @6 "${key_str}" = ${val} into ${ptr_str(t)}') unsafe { - util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'inserting @6 "${key}" = ${val} into ${ptr_str(t)}') - t[key.str()] = val + if _ := t[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()}..."') + } + t[key_str] = val } } else { p.ignore_while(space_formatting) key, val := p.key_value()! key_str := key.str() + util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'inserting @5 "${key_str}" = ${val} into ${ptr_str(tbl)}') 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} into ${ptr_str(tbl)}') tbl[key_str] = val } previous_token_was_value = true diff --git a/vlib/toml/tests/toml_lang_test.v b/vlib/toml/tests/toml_lang_test.v index d2e047cf88b29f..5527e4e2a5a82c 100644 --- a/vlib/toml/tests/toml_lang_test.v +++ b/vlib/toml/tests/toml_lang_test.v @@ -24,7 +24,6 @@ const valid_exceptions = [ // NOTE: entries in this list are tests of invalid TOML that should have the parser fail, but currently does not. const invalid_exceptions = [ 'do_not_remove', - 'inline-table/duplicate-key-02.toml', 'string/multiline-escape-space-02.toml', 'string/missing-quotes-array.toml', 'table/append-with-dotted-keys-05.toml',