From 1bee235c6d0c51697cfcbd2c71861ed2641897a9 Mon Sep 17 00:00:00 2001 From: "13621160019@163.com" <13621160019@163.com> Date: Fri, 11 Jun 2021 17:09:36 +0800 Subject: [PATCH] validate expression of rule in API --- myems-api/core/rule.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/myems-api/core/rule.py b/myems-api/core/rule.py index 0667cf10..d0a8dc00 100644 --- a/myems-api/core/rule.py +++ b/myems-api/core/rule.py @@ -115,6 +115,11 @@ class RuleCollection: title='API.BAD_REQUEST', description='API.INVALID_EXPRESSION') expression = str.strip(new_values['data']['expression']) + # validate expression in json + try: + json.loads(expression) + except Exception as ex: + raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description=ex) if 'message_template' not in new_values['data'].keys() or \ not isinstance(new_values['data']['message_template'], str) or \ @@ -305,6 +310,11 @@ class RuleItem: title='API.BAD_REQUEST', description='API.INVALID_EXPRESSION') expression = str.strip(new_values['data']['expression']) + # validate expression in json + try: + json.loads(expression) + except Exception as ex: + raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description=ex) if 'message_template' not in new_values['data'].keys() or \ not isinstance(new_values['data']['message_template'], str) or \