Skip to content

Commit 9dccf39

Browse files
author
BirdeeHub
committed
fix(tables): fixed edge case that allowed duplicate tables to be valid
1 parent d09db98 commit 9dccf39

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/decode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ static bool recursive_lua_nav(
7474
int deftype = lua_type(L, defidx); // get the type of the new defidx
7575
if (key_idx < keys_end) { // NOTE: not last key
7676
lua_Integer len = lua_tointeger(L, defidx);
77-
lua_pop(L, 1);
7877
if (len < 0) {
7978
TMLErr *err = new_tmlerr(L, DECODE_DEFINED_IDX);
8079
set_tmlerr(err, false, 33, "value already defined inline at: ");
8180
return err_push_keys(L, err, keys_start, keys_end);
8281
}
8382
if (deftype == LUA_TNUMBER) {
83+
lua_pop(L, 1);
8484
lua_rawgeti(L, validx, len);
8585
lua_replace(L, validx);
8686
lua_settop(L, validx);

tests/decode_tests.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,16 @@ key = 2
163163
]]
164164
local data, err = tomlua_default.decode(toml_str)
165165
it(err ~= nil, "should error on duplicate table")
166+
toml_str = [[
167+
[table]
168+
key = 1
169+
[table.ha]
170+
key = 1
171+
[table]
172+
key2 = 2
173+
]]
174+
data, err = tomlua_default.decode(toml_str)
175+
it(err ~= nil, "shouldn't forget about the duplicate tables")
166176
toml_str = [=[
167177
[fruit.oops]
168178
whelp = "hmmmm"

0 commit comments

Comments
 (0)