# HG changeset patch # User Matthew Wild <mwild1@gmail.com> # Date 1479243724 0 # Node ID 7e1d8c46d788bbc97fb5e091e57de4a8a0426253 # Parent 3ebd3cb4d7d296353a5543cd7aa1ad1e99b16535 mod_firewall: Support for default values in stanza paths diff -r 3ebd3cb4d7d2 -r 7e1d8c46d788 mod_firewall/mod_firewall.lua --- a/mod_firewall/mod_firewall.lua Tue Nov 15 15:01:14 2016 +0000 +++ b/mod_firewall/mod_firewall.lua Tue Nov 15 21:02:04 2016 +0000 @@ -47,10 +47,16 @@ return (s:gsub("$(%b())", [["..tostring(%1).."]]) :gsub("$(%b<>)", function (expr) expr = expr:sub(2,-2); + local default = expr:match("||([^|]+)$"); + if default then + expr = expr:sub(1, -(#default+2)); + else + default = "<undefined>"; + end if expr:match("^@") then - return "\"..stanza.attr["..("%q"):format(expr:sub(2)).."]..\""; + return "\"..(stanza.attr["..("%q"):format(expr:sub(2)).."] or "..("%q"):format(default)..")..\""; end - return "\"..stanza:find("..("%q"):format(expr:sub(2, -2))..")..\""; + return "\"..(stanza:find("..("%q"):format(expr:sub(2, -2))..") or "..("%q"):format(default)..")..\""; end) :gsub("$$(%a+)", extra or {}) :gsub([[^""%.%.]], "")