diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-08-07 14:42:30 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-08-07 14:42:30 +0100 |
commit | b9fb73ce0ba993c9873cf0022be7bb68766c8d83 (patch) | |
tree | 736367e27f35ca534567c549327a68dc2c7a3652 | |
parent | 890e7fe0e079b946c34986f5c65fbd05626486d0 (diff) | |
download | rspamd-b9fb73ce0ba993c9873cf0022be7bb68766c8d83.tar.gz rspamd-b9fb73ce0ba993c9873cf0022be7bb68766c8d83.zip |
[Fix] Fix merge table utility
-rw-r--r-- | lualib/lua_util.lua | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua index a68da0d59..6964b0f00 100644 --- a/lualib/lua_util.lua +++ b/lualib/lua_util.lua @@ -627,10 +627,23 @@ exports.table_cmp = table_cmp -- Merge two tables --]] local function table_merge(t1, t2) + local res = {} + local nidx = 1 -- for numeric indicies + local it_func = function(k, v) + if type(k) == 'number' then + res[nidx] = v + nidx = nidx + 1 + else + res[k] = v + end + end + for k, v in pairs(t1) do + it_func(k, v) + end for k, v in pairs(t2) do - t1[k] = v + it_func(k, v) end - return t1 + return res end exports.table_merge = table_merge |