From a762172bf748f6d4d590faaf9df50e778ebf09ba Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Mon, 3 Apr 2023 09:52:16 +0200 Subject: [PATCH] [fix] engine ddg: quote !bangs in a request send to ddg Closes: https://github.com/searxng/searxng/issues/392 Signed-off-by: Markus Heiser --- searx/engines/duckduckgo.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/searx/engines/duckduckgo.py b/searx/engines/duckduckgo.py index 85e977bdb..4dd23c759 100644 --- a/searx/engines/duckduckgo.py +++ b/searx/engines/duckduckgo.py @@ -6,6 +6,7 @@ DuckDuckGo Lite """ from typing import TYPE_CHECKING +import re from urllib.parse import urlencode import json import babel @@ -15,6 +16,7 @@ from searx import ( network, locales, redislib, + external_bang, ) from searx import redisdb from searx.utils import ( @@ -197,6 +199,17 @@ ddg_lang_map = { def request(query, params): + # quote ddg bangs + query_parts = [] + # for val in re.split(r'(\s+)', query): + for val in re.split(r'(\s+)', query): + if not val.strip(): + continue + if val.startswith('!') and external_bang.get_node(external_bang.EXTERNAL_BANGS, val[1:]): + val = f"'{val}'" + query_parts.append(val) + query = ' '.join(query_parts) + eng_region = traits.get_region(params['searxng_locale'], traits.all_locale) # eng_lang = get_ddg_lang(traits, params['searxng_locale'])