fix rare bug in highlight

This commit is contained in:
Your Name 2023-04-29 14:09:44 -04:00 committed by Henri Dickson
parent 81cc165afe
commit c89ebea5ac

View file

@ -12,11 +12,14 @@ register = template.Library()
@stringfilter
def highlight(text, search):
otext = cc.convert(text.lower())
l = len(text)
if l != len(otext):
return text # in rare cases, the lowered&converted text has a different length
rtext = ""
words = list(set([w for w in cc.convert(search.strip().lower()).split(" ") if w]))
words.sort(key=len, reverse=True)
i = 0
while i < len(otext):
while i < l:
m = None
for w in words:
if otext[i : i + len(w)] == w: