fix: comment mentions (#6611)

* fix: replace br with div

* test: Add test coverage
This commit is contained in:
Shreya Shah 2018-12-18 09:01:55 +05:30 committed by Rushabh Mehta
parent 3128723b09
commit 5e7e78c2de
2 changed files with 8 additions and 1 deletions

View file

@ -266,3 +266,10 @@ class TestUser(unittest.TestCase):
self.assertEqual(extract_mentions(user_name)[0], "test-user")
user_name = "Testing comment, @test.user@example.com please check."
self.assertEqual(extract_mentions(user_name)[0], "test.user@example.com")
user_name = "<div>@test_user@example.com and @test.again@example1.com</div><div>This is a test.</div>"
self.assertEqual(extract_mentions(user_name)[0], "test_user@example.com")
self.assertEqual(extract_mentions(user_name)[1], "test.again@example1.com")
user_name = "<div>@user@example.com</a> Test @test-comment@xyz.com</div><div>Test for comment mentions @test@abc.com</div>"
self.assertEqual(extract_mentions(user_name)[0], "user@example.com")
self.assertEqual(extract_mentions(user_name)[1], "test-comment@xyz.com")
self.assertEqual(extract_mentions(user_name)[2], "test@abc.com")

View file

@ -901,7 +901,7 @@ def notify_admin_access_to_system_manager(login_manager=None):
def extract_mentions(txt):
"""Find all instances of @name in the string.
The mentions will be separated by non-word characters or may appear at the start of the string"""
txt = txt.replace("<br>", "<br> ")
txt = txt.replace("<div>", "<div> ")
txt = re.sub(r'(<[a-zA-Z\/][^>]*>)', '', txt)
return re.findall(r'(?:[^\w\.\-\@]|^)@([\w\.\-\@]*)', txt)