From: Vsevolod Stakhov Date: Fri, 19 Jul 2019 12:11:46 +0000 (+0100) Subject: [Minor] Selectors: Filter empty values when doing map X-Git-Tag: 2.0~545 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9a9b633f5a5326681f41f9d0e8097fb83ffe5401;p=rspamd.git [Minor] Selectors: Filter empty values when doing map --- diff --git a/lualib/lua_selectors.lua b/lualib/lua_selectors.lua index a55d0742b..b4496a428 100644 --- a/lualib/lua_selectors.lua +++ b/lualib/lua_selectors.lua @@ -723,10 +723,12 @@ local function process_selector(task, sel) if meth.types[pt] then lua_util.debugm(M, task, 'map method `%s` to list of %s', meth.name, pt) - input = fun.map(function(list_elt) - local ret, _ = meth.process(list_elt, pt) - return ret - end, input) + -- Map method to a list of inputs, excluding empty elements + input = fun.filter(function(map_elt) return map_elt end, + fun.map(function(list_elt) + local ret, _ = meth.process(list_elt, pt) + return ret + end, input)) etype = 'string_list' end end @@ -743,10 +745,11 @@ local function process_selector(task, sel) etype = 'string' else lua_util.debugm(M, task, 'apply implicit map %s->string', pt) - input = fun.map(function(list_elt) - local ret = implicit_tostring(pt, list_elt) - return ret - end, input) + input = fun.filter(function(map_elt) return map_elt end, + fun.map(function(list_elt) + local ret = implicit_tostring(pt, list_elt) + return ret + end, input)) etype = 'string_list' end end @@ -773,12 +776,16 @@ local function process_selector(task, sel) local map_type = x.map_type .. '_list' lua_util.debugm(M, task, 'map `%s` to list of %s resulting %s', x.name, pt, map_type) - - return {fun.map(function(list_elt) - if not list_elt then return nil end - local ret, _ = x.process(list_elt, pt, x.args) - return ret - end, value), map_type} + -- Apply map, filtering empty values + return { + fun.filter(function(map_elt) return map_elt end, + fun.map(function(list_elt) + if not list_elt then return nil end + local ret, _ = x.process(list_elt, pt, x.args) + return ret + end, value)), + map_type -- Returned type + } end logger.errx(task, 'cannot apply transform %s for type %s', x.name, t) return nil