Daniel Brötzmann pushed to branch master at gajim / gajim


Commits:
f1fa4f75 by wurstsalat at 2025-08-03T17:13:55+02:00
fix: Improve nickname matching for preceding apostropes

Fixes #11918

- - - - -


2 changed files:

- gajim/common/util/muc.py
- test/common/test_message_needs_highlight.py


Changes:

=====================================
gajim/common/util/muc.py
=====================================
@@ -117,9 +117,17 @@ def message_needs_highlight(text: str, nickname: str, 
own_jid: str) -> bool:
                 # Text contains search_string only (exact match)
                 return True
 
+            # Exclude some characters preceding the match:
+            # - any alpha chars
+            # - / which may be commands
+            # - - which may connect multiple words
+            # - ' which may be part of a contraction, such as o'clock, 'tis
+            excluded_chars = ('/', '-', '\'')
+
+            char_before = text[match - 1]
             char_before_allowed = bool(
                 match == 0
-                or (not text[match - 1].isalpha() and text[match - 1] not in 
('/', '-'))
+                or (not char_before.isalpha() and char_before not in 
excluded_chars)
             )
 
             if char_before_allowed and search_end == len(text):


=====================================
test/common/test_message_needs_highlight.py
=====================================
@@ -35,6 +35,8 @@ def test_highlight(self):
         f_text2 = 'RomeoDoes this work?'
         f_text3 = 'nRomeo'
         f_text4 = 'nRomeoa'
+        f_text5 = "/Romeo"
+        f_text6 = "'Romeo"
         f_text_url_1 = 'https://romeo.tld'
         f_text_url_2 = 'https://romeo.tld message'
         f_text_url_3 = 'https://test.tld/where-is-romeo'
@@ -58,6 +60,8 @@ def test_highlight(self):
         self.assertFalse(message_needs_highlight(f_text2, NICK, JID))
         self.assertFalse(message_needs_highlight(f_text3, NICK, JID))
         self.assertFalse(message_needs_highlight(f_text4, NICK, JID))
+        self.assertFalse(message_needs_highlight(f_text5, NICK, JID))
+        self.assertFalse(message_needs_highlight(f_text6, NICK, JID))
         self.assertFalse(message_needs_highlight(f_text_url_1, NICK, JID))
         self.assertFalse(message_needs_highlight(f_text_url_2, NICK, JID))
         self.assertFalse(message_needs_highlight(f_text_url_3, NICK, JID))



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/f1fa4f75217597ad0ee18586b4045748d8165379

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/f1fa4f75217597ad0ee18586b4045748d8165379
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to