mirror of
https://github.com/searxng/searxng.git
synced 2025-07-14 16:59:21 +02:00
[fix] calculator plugin: crash when trying to evaluate non-math query (#4975)
Some checks are pending
Documentation / Release (push) Waiting to run
Integration / Python 3.11 (push) Waiting to run
Integration / Python 3.10 (push) Waiting to run
Integration / Python 3.12 (push) Waiting to run
Integration / Python 3.13 (push) Waiting to run
Integration / Python 3.9 (push) Waiting to run
Integration / Theme (push) Waiting to run
Some checks are pending
Documentation / Release (push) Waiting to run
Integration / Python 3.11 (push) Waiting to run
Integration / Python 3.10 (push) Waiting to run
Integration / Python 3.12 (push) Waiting to run
Integration / Python 3.13 (push) Waiting to run
Integration / Python 3.9 (push) Waiting to run
Integration / Theme (push) Waiting to run
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.
This commit is contained in:
parent
01be2612ab
commit
5926d737e3
1 changed files with 2 additions and 2 deletions
|
@ -170,8 +170,8 @@ def _eval_expr(expr):
|
||||||
root_expr = ast.parse(expr, mode='eval').body
|
root_expr = ast.parse(expr, mode='eval').body
|
||||||
return _eval(root_expr), isinstance(root_expr, ast.Compare)
|
return _eval(root_expr), isinstance(root_expr, ast.Compare)
|
||||||
|
|
||||||
except ZeroDivisionError:
|
except (SyntaxError, TypeError, ZeroDivisionError):
|
||||||
# This is undefined
|
# Expression that can't be evaluated (i.e. not a math expression)
|
||||||
return "", False
|
return "", False
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue