From d8dcdc74556569675911c6827db420f559e4a72f Mon Sep 17 00:00:00 2001 From: DUO Labs Date: Wed, 27 Oct 2021 12:50:21 -0400 Subject: [PATCH 01/15] Skip bolding search terms that are not alphanumeric (#496) Fixes #494 --- app/utils/results.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/utils/results.py b/app/utils/results.py index 0c04b76..c239a28 100644 --- a/app/utils/results.py +++ b/app/utils/results.py @@ -52,6 +52,9 @@ def bold_search_terms(response: str, query: str) -> BeautifulSoup: if len(element) == len(target_word): return + if not target_word.isalnum(): + return + element.replace_with( re.sub(fr'\b((?![{{}}<>-]){target_word}(?![{{}}<>-]))\b', r'\1', From b96e3a0acb6df2c0da1bb08a46f1ebe1c9842f56 Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Wed, 27 Oct 2021 11:02:14 -0600 Subject: [PATCH 02/15] Make base search url a member of the request class Since the request class is loaded prior to values being read from the user's dotenv, the WHOOGLE_RESULT_PER_PAGE var wasn't being used for searches. This moves the definition of the base search url to be intialized in the request class to address this issue. Fixes #497 --- app/request.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/request.py b/app/request.py index 0c80f9b..71f4e9b 100644 --- a/app/request.py +++ b/app/request.py @@ -9,8 +9,6 @@ import os from stem import Signal, SocketError from stem.control import Controller -SEARCH_URL = 'https://www.google.com/search?gbv=1&num=' + str( - os.getenv('WHOOGLE_RESULTS_PER_PAGE', 10)) + '&q=' MAPS_URL = 'https://maps.google.com/maps' AUTOCOMPLETE_URL = ('https://suggestqueries.google.com/' 'complete/search?client=toolbar&') @@ -151,6 +149,8 @@ class Request: """ def __init__(self, normal_ua, root_path, config: Config): + self.search_url = 'https://www.google.com/search?gbv=1&num=' + str( + os.getenv('WHOOGLE_RESULTS_PER_PAGE', 10)) + '&q=' # Send heartbeat to Tor, used in determining if the user can or cannot # enable Tor for future requests send_tor_signal(Signal.HEARTBEAT) @@ -224,7 +224,7 @@ class Request: return [_.attrib['data'] for _ in root.findall('.//suggestion/[@data]')] - def send(self, base_url=SEARCH_URL, query='', attempt=0, + def send(self, base_url='', query='', attempt=0, force_mobile=False) -> Response: """Sends an outbound request to a URL. Optionally sends the request using Tor, if enabled by the user. @@ -285,7 +285,7 @@ class Request: disable=True) response = requests.get( - base_url + query, + (base_url or self.search_url) + query, proxies=self.proxies, headers=headers, cookies=cookies) @@ -295,6 +295,6 @@ class Request: attempt += 1 if attempt > 10: raise TorError("Tor query failed -- max attempts exceeded 10") - return self.send(base_url, query, attempt) + return self.send((base_url or self.search_url), query, attempt) return response From 190b6844694f690f11f639c19c6c90e7157134ab Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Wed, 27 Oct 2021 12:30:55 -0600 Subject: [PATCH 03/15] Reformat view templates --- app/templates/display.html | 72 +++--- app/templates/header.html | 56 ++--- app/templates/index.html | 446 ++++++++++++++++++----------------- app/templates/opensearch.xml | 25 +- 4 files changed, 311 insertions(+), 288 deletions(-) diff --git a/app/templates/display.html b/app/templates/display.html index e9ec20b..4f2c109 100644 --- a/app/templates/display.html +++ b/app/templates/display.html @@ -1,45 +1,45 @@ - - - - - - - - - - {% if config.theme %} - {% if config.theme == 'system' %} + + + + + + + + + + {% if config.theme %} + {% if config.theme == 'system' %} - {% else %} - - {% endif %} {% else %} - + {% endif %} - - {{ clean_query(query) }} - Whoogle Search - - - {{ search_header|safe }} - {% if is_translation %} - + {% else %} + {% endif %} - {{ response|safe }} - - - - - + + {{ clean_query(query) }} - Whoogle Search + + +{{ search_header|safe }} +{% if is_translation %} + +{% endif %} +{{ response|safe }} + + + + + diff --git a/app/templates/header.html b/app/templates/header.html index 0ba701c..e9c04e2 100644 --- a/app/templates/header.html +++ b/app/templates/header.html @@ -2,8 +2,8 @@
+ id="search-form" + method="{{ 'GET' if config.get_only else 'POST' }}">