Escape the content of the regex in highligh_text

This commit is contained in:
Martin Pépin 2017-03-19 14:48:04 +00:00
parent 4899bba1f7
commit dc50a23b10
2 changed files with 2 additions and 2 deletions

View file

@ -23,7 +23,7 @@ def key(d, key_name):
def highlight_text(text, q):
q2 = "|".join(q.split())
q2 = "|".join(re.escape(word) for word in q.split())
pattern = re.compile(r"(?P<filter>%s)" % q2, re.IGNORECASE)
return mark_safe(re.sub(pattern,
r"<span class='highlight'>\g<filter></span>",

View file

@ -11,7 +11,7 @@ register = template.Library()
def highlight_text(text, q):
q2 = "|".join(q.split())
q2 = "|".join(re.escape(word) for word in q.split())
pattern = re.compile(r"(?P<filter>%s)" % q2, re.IGNORECASE)
regex = r"<span class='highlight_autocomplete'>\g<filter></span>"
return mark_safe(re.sub(pattern, regex, text))