changeset 962:93ffa3ffc66f

mod_firewall/conditions: Support Lua patterns in JID matching, and make <*>@example.com NOT match example.com
author Matthew Wild <mwild1@gmail.com>
date Fri, 05 Apr 2013 19:17:33 +0100
parents f0108ec2b016
children c7fca2c9e24f
files mod_firewall/conditions.lib.lua
diffstat 1 files changed, 8 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mod_firewall/conditions.lib.lua	Fri Apr 05 18:50:52 2013 +0100
+++ b/mod_firewall/conditions.lib.lua	Fri Apr 05 19:17:33 2013 +0100
@@ -24,11 +24,16 @@
 		return part.." == nil"
 	end
 	local pattern = match:match("<(.*)>");
-	-- TODO: Support Lua pattern matching (main issue syntax... << >>?)
 	if pattern then
-		if pattern ~= "*" then
-			return ("%s:match(%q)"):format(part, pattern:gsub(".", wildcard_equivs));
+		if pattern == "*" then
+			return part;
 		end
+		if pattern:match("^<.*>$") then
+			pattern = pattern:match("^<(.*)>$");
+		else
+			pattern = pattern:gsub("%p", "%%%0"):gsub("%%(%p)", wildcard_equivs);
+		end
+		return ("%s:match(%q)"):format(part, "^"..pattern.."$");
 	else
 		return ("%s == %q"):format(part, match);
 	end