Comparison

mod_firewall/mod_firewall.lua @ 2385:c0c2f8665c3e

mod_firewall: Fix for raw code expressions that contain escape-worthy characters
author Matthew Wild <mwild1@gmail.com>
date Sat, 19 Nov 2016 15:47:41 +0000
parent 2374:d630fa0d4dba
child 2402:2040330586e4
comparison
equal deleted inserted replaced
2384:feba6439b6fb 2385:c0c2f8665c3e
47 return name:match("^%a[%w_]*$") 47 return name:match("^%a[%w_]*$")
48 end 48 end
49 49
50 -- Run quoted (%q) strings through this to allow them to contain code. e.g.: LOG=Received: $(stanza:top_tag()) 50 -- Run quoted (%q) strings through this to allow them to contain code. e.g.: LOG=Received: $(stanza:top_tag())
51 function meta(s, extra) 51 function meta(s, extra)
52 return (s:gsub("$(%b())", [["..tostring(%1).."]]) 52 return (s:gsub("$(%b())", function (expr)
53 expr = expr:gsub("\\(.)", "%1");
54 return [["..tostring(]]..expr..[[).."]];
55 end)
53 :gsub("$(%b<>)", function (expr) 56 :gsub("$(%b<>)", function (expr)
54 expr = expr:sub(2,-2); 57 expr = expr:sub(2,-2);
55 local default = expr:match("||([^|]+)$"); 58 local default = expr:match("||([^|]+)$");
56 if default then 59 if default then
57 expr = expr:sub(1, -(#default+2)); 60 expr = expr:sub(1, -(#default+2));