[fix] engine ddg: quote !bangs in a request send to ddg

Closes: https://github.com/searxng/searxng/issues/392
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
Markus Heiser 2023-04-03 09:52:16 +02:00
parent b8100e4e16
commit a762172bf7

View file

@ -6,6 +6,7 @@ DuckDuckGo Lite
""" """
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
import re
from urllib.parse import urlencode from urllib.parse import urlencode
import json import json
import babel import babel
@ -15,6 +16,7 @@ from searx import (
network, network,
locales, locales,
redislib, redislib,
external_bang,
) )
from searx import redisdb from searx import redisdb
from searx.utils import ( from searx.utils import (
@ -197,6 +199,17 @@ ddg_lang_map = {
def request(query, params): 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_region = traits.get_region(params['searxng_locale'], traits.all_locale)
# eng_lang = get_ddg_lang(traits, params['searxng_locale']) # eng_lang = get_ddg_lang(traits, params['searxng_locale'])