Improve highlighing regex to deal with fancy nicknames

Nicknames which do not end and start on a word boundary or contain
regex metacharacters broke with the previous approach.

Fixes #3433.
This commit is contained in:
Jonas Schäfer 2018-09-25 18:53:10 +02:00 committed by Emmanuel Gil Peyrot
parent 4b8c63d25b
commit 6deffb430e

View file

@ -1251,11 +1251,14 @@ class MucTab(ChatTab):
1, self.width, self.height - 2 - self.core.information_win_size - 1, self.width, self.height - 2 - self.core.information_win_size -
Tab.tab_win_height(), 0) Tab.tab_win_height(), 0)
def build_highlight_regex(self, nickname):
return re.compile(r"(^|\W)" + re.escape(nickname) + r"(\W|$)", re.I)
def is_highlight(self, txt, time, nickname, own_nick, highlight_on, def is_highlight(self, txt, time, nickname, own_nick, highlight_on,
corrected=False): corrected=False):
highlighted = False highlighted = False
if (not time or corrected) and nickname and nickname != own_nick: if (not time or corrected) and nickname and nickname != own_nick:
if re.search(r'\b' + own_nick.lower() + r'\b', txt.lower()): if self.build_highlight_regex(own_nick).search(txt):
highlighted = True highlighted = True
else: else:
highlight_words = highlight_on.split(':') highlight_words = highlight_on.split(':')