diff options
| author | Bnyro <bnyro@tutanota.com> | 2025-07-04 21:32:54 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-04 21:32:54 +0200 |
| commit | 5926d737e3c93fcaafd806c013b207a2d1813b0b (patch) | |
| tree | ff67baa71e82d21581a5d1b6da4cba2d4ed853ef /searx/plugins | |
| parent | 01be2612ab845771929181592931464f179357ea (diff) | |
[fix] calculator plugin: crash when trying to evaluate non-math query (#4975)
It's possible that `SyntaxError` or `TypeError` instances are thrown
when we can't evaluate a query, simply because it's not a math expression.
In this case, it should just be skipped, i.e. the calculator plugin doesn't
return any result instead of forwarding the exception.
Diffstat (limited to 'searx/plugins')
| -rw-r--r-- | searx/plugins/calculator.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/searx/plugins/calculator.py b/searx/plugins/calculator.py index ba9dc8721..af44eea1e 100644 --- a/searx/plugins/calculator.py +++ b/searx/plugins/calculator.py @@ -170,8 +170,8 @@ def _eval_expr(expr): root_expr = ast.parse(expr, mode='eval').body return _eval(root_expr), isinstance(root_expr, ast.Compare) - except ZeroDivisionError: - # This is undefined + except (SyntaxError, TypeError, ZeroDivisionError): + # Expression that can't be evaluated (i.e. not a math expression) return "", False |