diff mod_firewall/mod_firewall.lua @ 2538:a1b6a6b0aabb

mod_firewall: Reinstate the ability to set a default for stanza expressions
author Matthew Wild <mwild1@gmail.com>
date Tue, 21 Feb 2017 10:37:53 +0000
parents 9aed7f4e9f07
children 1510b66a43fc
line wrap: on
line diff
--- a/mod_firewall/mod_firewall.lua	Tue Feb 21 10:37:10 2017 +0000
+++ b/mod_firewall/mod_firewall.lua	Tue Feb 21 10:37:53 2017 +0000
@@ -70,6 +70,11 @@
 		end)
 		:gsub("$(%b<>)", function (expr)
 			expr = expr:sub(2,-2);
+			local default = "<undefined>";
+			expr = expr:gsub("||(%b\"\")$", function (s)
+				default = s:sub(2,-2);
+				return "";
+			end);
 			local func_chain = expr:match("|[%w|]+$");
 			if func_chain then
 				expr = expr:sub(1, -1-#func_chain);
@@ -113,14 +118,13 @@
 					end
 				end
 			end
-			return "\"..tostring(("..code..") or \"<undefined>\")..\"";
+			return "\"..tostring("..code.." or "..("%q"):format(default)..")..\"";
 		end)
 		:gsub("$$(%a+)", extra or {})
 		:gsub([[^""%.%.]], "")
 		:gsub([[%.%.""$]], ""));
 end
 
-
 -- Dependency locations:
 -- <type lib>
 -- <type global>