diff options
author | Jonas Schäfer <j.wielicki@sotecware.net> | 2018-09-25 18:53:10 +0200 |
---|---|---|
committer | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2018-09-25 18:59:37 +0200 |
commit | 6deffb430ef044938f1ed20fa2fdd47022d44970 (patch) | |
tree | 5607ac9f1ad8785bb30592bba1961d968a22bcc9 | |
parent | 4b8c63d25bd76d9dfc69bfb778b2f500e0613c17 (diff) | |
download | poezio-6deffb430ef044938f1ed20fa2fdd47022d44970.tar.gz poezio-6deffb430ef044938f1ed20fa2fdd47022d44970.tar.bz2 poezio-6deffb430ef044938f1ed20fa2fdd47022d44970.tar.xz poezio-6deffb430ef044938f1ed20fa2fdd47022d44970.zip |
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.
-rw-r--r-- | poezio/tabs/muctab.py | 5 |
1 files changed, 4 insertions, 1 deletions
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(':') |