summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Kozak <spag@golwen.net>2013-06-14 11:14:04 +0200
committerPeter Kozak <spag@golwen.net>2013-06-14 11:14:04 +0200
commite48434bf0e1bac7687d08734578c01367b880562 (patch)
treef6830dfee089d8a6ed637425d1971dd9ee935bd5
parent66ef95959eabf843832eeae4c844cbd05eabd5e3 (diff)
expression can be nil, empty or invalid
-rw-r--r--misc/freeswitch/scripts/dialplan/router.lua20
1 files changed, 18 insertions, 2 deletions
diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua
index c2b229d..b762010 100644
--- a/misc/freeswitch/scripts/dialplan/router.lua
+++ b/misc/freeswitch/scripts/dialplan/router.lua
@@ -278,8 +278,24 @@ end
function Router.fun_expression(self, expression_str)
- expression_str = expression_str:gsub('[^%d%.%+%(%)%^%%%*%/-<>]', '');
- result = loadstring("return (" .. expression_str .. ")")();
+ if common.str.blank(expression_str) then
+ self.log:error('EXPRESSION - no expression specified');
+ return false;
+ end
+
+ expression_str = expression_str:gsub('[^%d%.%+%(%)%^%%%*%/-<>=!|&]', '');
+ expression_str = expression_str:gsub('&&', ' and ');
+ expression_str = expression_str:gsub('||', ' or ');
+ expression_str = expression_str:gsub('!=', '~=');
+
+ local expression = loadstring("return (" .. expression_str .. ")")
+
+ if not expression then
+ self.log:error('EXPRESSION - invalid expression: ', expression_str);
+ return false;
+ end
+
+ result = expression();
if result then
return true, result;
else