Browse Source

[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
Solirs 2 years ago
parent
commit
fbb0e9d275
1 changed files with 3 additions and 1 deletions
  1. 3 1
      searx/webutils.py

+ 3 - 1
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))
             queries.extend(re.findall(regex_highlight_cjk(qs), content, flags=re.I | re.U))
     if len(queries) > 0:
     if len(queries) > 0:
         for q in set(queries):
         for q in set(queries):
-            content = re.sub(regex_highlight_cjk(q), f'<span class="highlight">{q}</span>', content)
+            content = re.sub(
+                regex_highlight_cjk(q), f'<span class="highlight">{q}</span>'.replace('\\', r'\\'), content
+            )
     return content
     return content