commit a1b9dff: [Fix] Fix text selectors

Vsevolod Stakhov vsevolod at highsecure.ru
Thu Nov 26 12:35:07 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-11-26 12:29:09 +0000
URL: https://github.com/rspamd/rspamd/commit/a1b9dffcf77bbb129d267a422e68721f9e034f11 (HEAD -> master)

[Fix] Fix text selectors

---
 lualib/lua_selectors/init.lua | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/lualib/lua_selectors/init.lua b/lualib/lua_selectors/init.lua
index 3839cec9e..cc44d0b01 100644
--- a/lualib/lua_selectors/init.lua
+++ b/lualib/lua_selectors/init.lua
@@ -456,12 +456,24 @@ exports.combine_selectors = function(_, selectors, delimiter)
 
   if not selectors then return nil end
 
-  local all_strings = fun.all(function(s) return type(s) == 'string' end, selectors)
+  local have_tables, have_userdata
 
-  if all_strings then
-    return table.concat(selectors, delimiter)
+  for _,s in ipairs(selectors) do
+    if type(s) == 'table' then
+      have_tables = true
+    elseif type(s) == 'userdata' then
+      have_userdata = true
+    end
+  end
+
+  if not have_tables then
+    if not have_userdata then
+      return table.concat(selectors, delimiter)
+    else
+      return rspamd_text.fromtable(selectors, delimiter)
+    end
   else
-    -- We need to do a spill on each table selector
+    -- We need to do a spill on each table selector and make a cortezian product
     -- e.g. s:tbl:s -> s:telt1:s + s:telt2:s ...
     local tbl = {}
     local res = {}
@@ -472,6 +484,7 @@ exports.combine_selectors = function(_, selectors, delimiter)
       elseif type(s) == 'userdata' then
         rawset(tbl, i, fun.duplicate(tostring(s)))
       else
+        -- Raw table
         rawset(tbl, i, s)
       end
     end


More information about the Commits mailing list