From 6deffb430ef044938f1ed20fa2fdd47022d44970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sch=C3=A4fer?= Date: Tue, 25 Sep 2018 18:53:10 +0200 Subject: 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. --- poezio/tabs/muctab.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py index 55275337..17ab3430 100644 --- a/poezio/tabs/muctab.py +++ b/poezio/tabs/muctab.py @@ -1251,11 +1251,14 @@ class MucTab(ChatTab): 1, self.width, self.height - 2 - self.core.information_win_size - 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, corrected=False): highlighted = False 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 else: highlight_words = highlight_on.split(':') -- cgit v1.2.3