From: Vsevolod Stakhov Date: Tue, 23 Jul 2019 17:02:16 +0000 (+0100) Subject: [Minor] Lua_selectors: Allow to index numeric arrays in selectors X-Git-Tag: 2.0~505 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2393156481374420919438468e2eda7725607635;p=rspamd.git [Minor] Lua_selectors: Allow to index numeric arrays in selectors --- diff --git a/lualib/lua_selectors.lua b/lualib/lua_selectors.lua index efe332878..c123ae637 100644 --- a/lualib/lua_selectors.lua +++ b/lualib/lua_selectors.lua @@ -1027,8 +1027,12 @@ exports.parse_selector = function(cfg, str) if proc_name:match('^__') then -- Special case - method local method_name = proc_name:match('^__(.*)$') + -- Check array indexing... + if tonumber(method_name) then + method_name = tonumber(method_name) + end local processor = { - name = method_name, + name = tostring(method_name), method = true, args = proc_tbl[2] or E, types = { @@ -1052,7 +1056,7 @@ exports.parse_selector = function(cfg, str) if not transform_function[proc_name] then logger.errx(cfg, 'processor %s is unknown', proc_name) - pipeline_error = true + pipeline_error = proc_name return nil end local processor = lua_util.shallowcopy(transform_function[proc_name]) @@ -1060,7 +1064,7 @@ exports.parse_selector = function(cfg, str) processor.args = proc_tbl[2] or E if not check_args(processor.name, processor.args_schema, processor.args) then - pipeline_error = true + pipeline_error = 'args schema for ' .. proc_name return nil end @@ -1071,7 +1075,7 @@ exports.parse_selector = function(cfg, str) end, fun.tail(sel)) if pipeline_error then - logger.errx(cfg, 'unknown or invalid processor used, exiting') + logger.errx(cfg, 'unknown or invalid processor used: "%s", exiting', pipeline_error) return nil end diff --git a/test/lua/unit/selectors.lua b/test/lua/unit/selectors.lua index 2fb839be1..cb3e61f8f 100644 --- a/test/lua/unit/selectors.lua +++ b/test/lua/unit/selectors.lua @@ -271,6 +271,10 @@ context("Selectors test", function() selector = "words('norm')", expect = {{'hello', 'world', 'mail', 'me'}} }, + ["words_full"] = { + selector = "words('full'):2", + expect = {{'hello', 'world', '', 'mail', 'me'}} + }, } for case_name, case in pairs(cases) do