commit 2393156: [Minor] Lua_selectors: Allow to index numeric arrays in selectors

Vsevolod Stakhov vsevolod at highsecure.ru
Tue Jul 23 17:07:05 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-07-23 18:02:16 +0100
URL: https://github.com/rspamd/rspamd/commit/2393156481374420919438468e2eda7725607635 (HEAD -> master)

[Minor] Lua_selectors: Allow to index numeric arrays in selectors

---
 lualib/lua_selectors.lua    | 12 ++++++++----
 test/lua/unit/selectors.lua |  4 ++++
 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


More information about the Commits mailing list