From 6696f2b12b4141fc3dde9f17c87d5e90f2efd51f Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Mon, 31 Oct 2022 12:45:44 -0600 Subject: [PATCH] Escape word in term-bolding regex Fixes #869 --- app/utils/results.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/utils/results.py b/app/utils/results.py index 2bb522b..408590e 100644 --- a/app/utils/results.py +++ b/app/utils/results.py @@ -63,6 +63,9 @@ def bold_search_terms(response: str, query: str) -> BeautifulSoup: if len(element) == len(target_word): return + # Ensure target word is escaped for regex + target_word = re.escape(target_word) + if re.match('.*[@_!#$%^&*()<>?/\|}{~:].*', target_word) or ( element.parent and element.parent.name == 'style'): return @@ -417,7 +420,7 @@ def get_tabs_content(tabs: dict, if tab_content['tbm'] is not None: query = f"{query}&tbm={tab_content['tbm']}" - + if preferences: query = f"{query}&preferences={preferences}"