diff --git a/activities/models/post.py b/activities/models/post.py index 98218d0..96288a3 100644 --- a/activities/models/post.py +++ b/activities/models/post.py @@ -342,7 +342,7 @@ class Post(StatorModel): PostTypeData.parse_obj(value) mention_regex = re.compile( - r"(^|[^\w\d\-_/])@([\w\d\-_]+(?:@[\w\d\-_]+\.[\w\d\-_\.]+)?)" + r"(^|[^\w\d\-_/])@([\w\d\-_]+(?:@[\w\d\-_\.]+[\w\d\-_]+)?)" ) def linkify_mentions(self, content: str, local: bool = False) -> str: diff --git a/tests/activities/models/test_post.py b/tests/activities/models/test_post.py index 0c4d103..48877fa 100644 --- a/tests/activities/models/test_post.py +++ b/tests/activities/models/test_post.py @@ -77,6 +77,7 @@ def test_linkify_mentions_remote( local=True, ) assert post.safe_content_remote() == "
@test@example.com, welcome!
" + # Test case insensitivity (remote) post = Post.objects.create( content="Hey @TeSt
", @@ -89,6 +90,18 @@ def test_linkify_mentions_remote( == 'Hey @test
' ) + # Test trailing dot (remote) + post = Post.objects.create( + content="Hey @test@remote.test.
", + author=identity, + local=True, + ) + post.mentions.add(remote_identity) + assert ( + post.safe_content_remote() + == 'Hey @test.
' + ) + # Test that collapsing only applies to the first unique, short username post = Post.objects.create( content="Hey @TeSt@remote.test and @test@remote2.test
",