summaryrefslogtreecommitdiff
path: root/searx/external_bang.py
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2022-01-11 08:55:10 +0100
committerMarkus Heiser <markus.heiser@darmarit.de>2022-01-11 09:58:10 +0100
commit6d7e86eece852a525ac2ec3c191aca57712ac1a7 (patch)
treea450b3cd3238281f44e760b4d7e55e3e7f17cb32 /searx/external_bang.py
parentf4004133b605cea8225c720a7f4c593d4c20d13e (diff)
downloadsearxng-6d7e86eece852a525ac2ec3c191aca57712ac1a7.tar.gz
searxng-6d7e86eece852a525ac2ec3c191aca57712ac1a7.zip
[fix] get_bang_url: handle ambiguous !!bangs without error
An ambiguous bang like `!!d` raises an exception in function get_bang_url(). A bang is only unique when the bang_definition from get_bang_definition_and_ac() is a string / for a ambiguous bang the returned bang_definition is a dictionary. Reported-by: user prg at #searxng:matrix.org on 2022/01/11 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/external_bang.py')
-rw-r--r--searx/external_bang.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/searx/external_bang.py b/searx/external_bang.py
index f8e872693..ec5a46ed0 100644
--- a/searx/external_bang.py
+++ b/searx/external_bang.py
@@ -77,11 +77,14 @@ def get_bang_url(search_query, external_bangs_db=None):
:param search_query: This is a search_query object which contains preferences and the submitted queries.
:return: None if the bang was invalid, else a string of the redirect url.
"""
+ ret_val = None
+
if external_bangs_db is None:
external_bangs_db = EXTERNAL_BANGS
if search_query.external_bang:
bang_definition, _ = get_bang_definition_and_ac(external_bangs_db, search_query.external_bang)
- return resolve_bang_definition(bang_definition, search_query.query)[0] if bang_definition else None
+ if bang_definition and isinstance(bang_definition, str):
+ ret_val = resolve_bang_definition(bang_definition, search_query.query)[0]
- return None
+ return ret_val