summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Godwin2022-11-21 22:17:22 -0700
committerAndrew Godwin2022-11-21 22:17:22 -0700
commit63ab492439ce4711fe6370d63bc6a55a48121448 (patch)
treee0c8434447982e63feef3df1c5cdc6a8244cd883
parent1d37dce0123d5746603e88678997edb562d61691 (diff)
downloadtakahe-63ab492439ce4711fe6370d63bc6a55a48121448.tar.gz
takahe-63ab492439ce4711fe6370d63bc6a55a48121448.tar.bz2
takahe-63ab492439ce4711fe6370d63bc6a55a48121448.zip
Fix mentions at the start of posts
-rw-r--r--activities/models/post.py2
-rw-r--r--tests/activities/models/test_post.py11
2 files changed, 12 insertions, 1 deletions
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()
== '<p><a href="/@test@example.com/">@test@example.com</a>, welcome!</p>'
)
+ # Test a full username (remote) with no <p>
+ post = Post.objects.create(
+ content="@test@remote.test hello!",
+ author=identity,
+ local=True,
+ )
+ post.mentions.add(remote_identity)
+ assert (
+ post.safe_content_local()
+ == '<a href="/@test@remote.test/">@test@remote.test</a> hello!'
+ )
# Test that they don't get touched without a mention
post = Post.objects.create(
content="<p>@test@example.com, welcome!</p>",