diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2022-12-21 11:40:25 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2022-12-21 11:40:25 +0000 |
commit | 532701a530a30fee3dfb120472e6d4a97f533fc6 (patch) | |
tree | 5b2687c793eae6f4b973eef36d9283fdf3d3bd9e /lualib | |
parent | 97e048959fff2d9db4ad3b2723e97719477a807d (diff) | |
download | rspamd-532701a530a30fee3dfb120472e6d4a97f533fc6.tar.gz rspamd-532701a530a30fee3dfb120472e6d4a97f533fc6.zip |
[Fix] Rework lists applications
Diffstat (limited to 'lualib')
-rw-r--r-- | lualib/lua_selectors/init.lua | 15 | ||||
-rw-r--r-- | lualib/lua_selectors/transforms.lua | 5 |
2 files changed, 12 insertions, 8 deletions
diff --git a/lualib/lua_selectors/init.lua b/lualib/lua_selectors/init.lua index da0ca104f..5823fef96 100644 --- a/lualib/lua_selectors/init.lua +++ b/lualib/lua_selectors/init.lua @@ -113,12 +113,18 @@ local function process_selector(task, sel) lua_util.debugm(M, task, 'map method `%s` to list of %s', meth.name, pt) -- Map method to a list of inputs, excluding empty elements - input = fun.filter(function(map_elt) return map_elt end, + -- We need to fold it down here to get a proper type resolution + input = fun.totable(fun.filter(function(map_elt, _) return map_elt end, fun.map(function(list_elt) - local ret, _ = meth.process(list_elt, pt, meth.args) + local ret, ty = meth.process(list_elt, pt, meth.args) + etype = ty return ret - end, input)) - etype = 'string_list' + end, input))) + if input and etype then + etype = etype .. "_list" + else + input = nil + end end end -- Remove method from the pipeline @@ -195,7 +201,6 @@ local function process_selector(task, sel) local pt = pure_type(res[2]) if pt then - lua_util.debugm(M, task, 'apply implicit map %s->string_list', pt) res[1] = fun.map(function(e) return implicit_tostring(pt, e) end, res[1]) res[2] = 'string_list' diff --git a/lualib/lua_selectors/transforms.lua b/lualib/lua_selectors/transforms.lua index f6a0b0a37..55e1bffb7 100644 --- a/lualib/lua_selectors/transforms.lua +++ b/lualib/lua_selectors/transforms.lua @@ -135,7 +135,7 @@ local transform_function = { -- Joins tables into a table of strings ['join_tables'] = { ['types'] = { - ['string_list'] = true + ['list'] = true }, ['process'] = function(inp, _, args) local sep = args[1] or '' @@ -521,8 +521,7 @@ Empty string comes the first argument or 'true', non-empty string comes nil]], for _,arg in ipairs(args) do local meth = inp[arg] local ret = meth(inp) - if not ret then return nil end - table.insert(res, tostring(ret)) + if ret then table.insert(res, tostring(ret)) end end return res,'string_list' end, |