From: Vsevolod Stakhov Date: Thu, 24 Nov 2016 13:42:23 +0000 (+0000) Subject: [Fix] Fix set and regexp like static maps X-Git-Tag: 1.4.1~75 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=664eeeca185f4f4c15f0124ade8bc9d6c3c6d537;p=thirdparty%2Frspamd.git [Fix] Fix set and regexp like static maps --- diff --git a/src/lua/global_functions.lua b/src/lua/global_functions.lua index 8c0514d94e..e89a5da644 100644 --- a/src/lua/global_functions.lua +++ b/src/lua/global_functions.lua @@ -451,29 +451,37 @@ function rspamd_map_add(mname, optname, mtype, description) end end - ret.__data = data - ret.get_key = function(t, k) - for _,re in ipairs(t.__data) do - if re:match(k) then return true end - end + if #data > 0 then + ret.__data = data + ret.get_key = function(t, k) + for _,re in ipairs(t.__data) do + if re:match(k) then return true end + end - return nil + return nil + end + return ret end else local data = {} + local nelts = 0 for _,elt in ipairs(opt) do if type(elt) == 'string' then data[elt] = true + nelts = nelts + 1 end end - ret.__data = data - ret.get_key = function(t, k) - if k ~= '__data' then - return t.__data[k] - end + if nelts > 0 then + ret.__data = data + ret.get_key = function(t, k) + if k ~= '__data' then + return t.__data[k] + end - return nil + return nil + end + return ret end end else