diff --git a/AUTHORS.rst b/AUTHORS.rst
index 036ae0fe1..b44a10b55 100644
--- a/AUTHORS.rst
+++ b/AUTHORS.rst
@@ -154,6 +154,6 @@ generally made searx better:
- @mrwormo
- Xiaoyu WEI @xywei
- @joshu9h
-
+- Daniel Hones
diff --git a/searx/webutils.py b/searx/webutils.py
index 8be8fcecd..2464a097f 100644
--- a/searx/webutils.py
+++ b/searx/webutils.py
@@ -119,7 +119,10 @@ def highlight_content(content, query):
else:
regex_parts = []
for chunk in query.split():
- if len(chunk) == 1:
+ chunk = chunk.replace('"', '')
+ if len(chunk) == 0:
+ continue
+ elif len(chunk) == 1:
regex_parts.append('\\W+{0}\\W+'.format(re.escape(chunk)))
else:
regex_parts.append('{0}'.format(re.escape(chunk)))
diff --git a/tests/unit/test_webutils.py b/tests/unit/test_webutils.py
index aa464688b..023374b04 100644
--- a/tests/unit/test_webutils.py
+++ b/tests/unit/test_webutils.py
@@ -34,6 +34,28 @@ class TestWebUtils(SearxTestCase):
query = 'a test'
self.assertEqual(webutils.highlight_content(content, query), content)
+ data = (
+ ('" test "',
+ 'a test string',
+ 'a test string'),
+ ('"a"',
+ 'this is a test string',
+ 'this is a test string'),
+ ('a test',
+ 'this is a test string that matches entire query',
+ 'this is a test string that matches entire query'),
+ ('this a test',
+ 'this is a string to test.',
+ ('this is a '
+ 'string to test.')),
+ ('match this "exact phrase"',
+ 'this string contains the exact phrase we want to match',
+ ('this string contains the exact'
+ ' phrase we want to match'))
+ )
+ for query, content, expected in data:
+ self.assertEqual(webutils.highlight_content(content, query), expected)
+
class TestUnicodeWriter(SearxTestCase):