From fbb0e9d27509f30242c531c0d5e83c845f6a03eb Mon Sep 17 00:00:00 2001 From: Solirs Date: Thu, 16 Mar 2023 20:29:14 +0100 Subject: [PATCH] [fix] server side error: escape backslashes in the query highlight_content Any backslash escapes in the replacement are processed [1], backslashes should be escaped [2]. [1] https://docs.python.org/3/library/re.html#re.sub [2] https://docs.python.org/3/library/re.html#re.escape closes: - https://github.com/searxng/searxng/issues/2256 - https://github.com/searxng/searxng/issues/2250 --- searx/webutils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/searx/webutils.py b/searx/webutils.py index 7b9a8045c..6c023ebc3 100644 --- a/searx/webutils.py +++ b/searx/webutils.py @@ -174,7 +174,9 @@ def highlight_content(content, query): queries.extend(re.findall(regex_highlight_cjk(qs), content, flags=re.I | re.U)) if len(queries) > 0: for q in set(queries): - content = re.sub(regex_highlight_cjk(q), f'{q}', content) + content = re.sub( + regex_highlight_cjk(q), f'{q}'.replace('\\', r'\\'), content + ) return content