Fix comment mentions to avoid html tags (#5865)

* Fix comment mentions to avoid html tags

* Add a test case
This commit is contained in:
Shreya Shah 2018-07-24 16:34:18 +05:30 committed by Rushabh Mehta
parent a0a23c1ead
commit b2fbb35efa
2 changed files with 3 additions and 0 deletions

View file

@ -260,6 +260,8 @@ class TestUser(unittest.TestCase):
def test_comment_mentions(self):
user_name = "@test.comment@example.com"
self.assertEqual(extract_mentions(user_name)[0], "test.comment@example.com")
user_name = "@test.comment@test-example.com"
self.assertEqual(extract_mentions(user_name)[0], "test.comment@test-example.com")
user_name = "Testing comment, @test-user please check."
self.assertEqual(extract_mentions(user_name)[0], "test-user")
user_name = "Testing comment, @test.user@example.com please check."

View file

@ -901,6 +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 = re.sub(r'(<[a-zA-Z\/][^>]*>)', '', txt)
return re.findall(r'(?:[^\w\.\-\@]|^)@([\w\.\-\@]*)', txt)