commit 9a9b633: [Minor] Selectors: Filter empty values when doing map
Vsevolod Stakhov
vsevolod at highsecure.ru
Fri Jul 19 12:56:04 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-07-19 13:11:46 +0100
URL: https://github.com/rspamd/rspamd/commit/9a9b633f5a5326681f41f9d0e8097fb83ffe5401
[Minor] Selectors: Filter empty values when doing map
---
lualib/lua_selectors.lua | 35 +++++++++++++++++++++--------------
1 file changed, 21 insertions(+), 14 deletions(-)
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
More information about the Commits
mailing list