diff --git a/activities/models/post.py b/activities/models/post.py index da23742..378de91 100644 --- a/activities/models/post.py +++ b/activities/models/post.py @@ -166,7 +166,7 @@ class Post(StatorModel): ### Content cleanup and extraction ### 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, local=False): diff --git a/tests/activities/models/test_post.py b/tests/activities/models/test_post.py index 6d86781..9d5207c 100644 --- a/tests/activities/models/test_post.py +++ b/tests/activities/models/test_post.py @@ -94,6 +94,17 @@ def test_linkify_mentions_local(identity, remote_identity): post.safe_content_local() == '

@test@example.com, welcome!

' ) + # Test a full username (remote) with no

+ post = Post.objects.create( + content="@test@remote.test hello!", + author=identity, + local=True, + ) + post.mentions.add(remote_identity) + assert ( + post.safe_content_local() + == '@test@remote.test hello!' + ) # Test that they don't get touched without a mention post = Post.objects.create( content="

@test@example.com, welcome!

",