summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-07-23 18:02:16 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-07-23 18:02:16 +0100
commit2393156481374420919438468e2eda7725607635 (patch)
treeb0b3914bf651ecb9736bfc4ac1a7c7d4f8e0399d
parent0de3deeadb49872e4b2eecf74faa2741d45a2bab (diff)
downloadrspamd-2393156481374420919438468e2eda7725607635.tar.gz
rspamd-2393156481374420919438468e2eda7725607635.zip
[Minor] Lua_selectors: Allow to index numeric arrays in selectors
-rw-r--r--lualib/lua_selectors.lua12
-rw-r--r--test/lua/unit/selectors.lua4
2 files changed, 12 insertions, 4 deletions
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