Merge pull request #2309 from return42/fix-392

[fix] engine ddg: quote !bangs in a request send to ddg
This commit is contained in:
Markus Heiser 2023-04-03 09:59:16 +02:00 committed by GitHub
commit 464e69665c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 0 deletions

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'])