Skip to content

Commit

Permalink
[fix] engine: duckduckgo - don't quote query string
Browse files Browse the repository at this point in the history
The query string send to DDG must not be qouted.

The query string was URL-qouted in searxng#4011, but the URL-qouted query string result
in unexpected *URL decoded* and other garbish results as reported in searxng#4019
and searxng#4020.  To test compare the results of a query like::

    !ddg Häuser und Straßen :de
    !ddg Häuser und Straßen :all
    !ddg 房屋和街道 :all
    !ddg 房屋和街道 :zh

Closed:

- [searxng#4019] searxng#4019
- [searxng#4020] searxng#4020

Related:

- [searxng#4011] searxng#4011

Signed-off-by: Markus Heiser <[email protected]>
  • Loading branch information
return42 committed Nov 17, 2024
1 parent 4b57bc3 commit 10d3af8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions searx/engines/duckduckgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from typing import TYPE_CHECKING
import re
from urllib.parse import urlencode, quote_plus
from urllib.parse import urlencode
import json
import babel
import lxml.html
Expand Down Expand Up @@ -263,7 +263,7 @@ def request(query, params):

params['url'] = url
params['method'] = 'POST'
params['data']['q'] = quote_plus(query)
params['data']['q'] = query

# The API is not documented, so we do some reverse engineering and emulate
# what https://html.duckduckgo.com/html does when you press "next Page" link
Expand Down Expand Up @@ -381,7 +381,11 @@ def response(resp):
zero_click_info_xpath = '//div[@id="zero_click_abstract"]'
zero_click = extract_text(eval_xpath(doc, zero_click_info_xpath)).strip()

if zero_click and "Your IP address is" not in zero_click and "Your user agent:" not in zero_click:
if zero_click and (
"Your IP address is" not in zero_click
and "Your user agent:" not in zero_click
and "URL Decoded:" not in zero_click
):
current_query = resp.search_params["data"].get("q")

results.append(
Expand Down

0 comments on commit 10d3af8

Please sign in to comment.