mod_firewall: Fix for raw code expressions that contain escape-worthy characters
authorMatthew Wild <mwild1@gmail.com>
Sat, 19 Nov 2016 15:47:41 +0000
changeset 2389 c0c2f8665c3e
parent 2388 feba6439b6fb
child 2390 00eed68f63bf
mod_firewall: Fix for raw code expressions that contain escape-worthy characters
mod_firewall/mod_firewall.lua
--- a/mod_firewall/mod_firewall.lua	Sat Nov 19 19:40:29 2016 +0100
+++ b/mod_firewall/mod_firewall.lua	Sat Nov 19 15:47:41 2016 +0000
@@ -49,7 +49,10 @@
 
 -- Run quoted (%q) strings through this to allow them to contain code. e.g.: LOG=Received: $(stanza:top_tag())
 function meta(s, extra)
-	return (s:gsub("$(%b())", [["..tostring(%1).."]])
+	return (s:gsub("$(%b())", function (expr)
+			expr = expr:gsub("\\(.)", "%1");
+			return [["..tostring(]]..expr..[[).."]];
+		end)
 		:gsub("$(%b<>)", function (expr)
 			expr = expr:sub(2,-2);
 			local default = expr:match("||([^|]+)$");