diff --git a/bookwyrm/tests/views/test_status.py b/bookwyrm/tests/views/test_status.py
index d02c71374..6863c9625 100644
--- a/bookwyrm/tests/views/test_status.py
+++ b/bookwyrm/tests/views/test_status.py
@@ -456,6 +456,16 @@ http://www.fish.com/"""
views.status.format_links(url), f'{url[8:]}'
)
+ def test_format_links_with_at_symbol(self, *_):
+ """A link with an @username shouldn't treat the username as a mention"""
+ content = "a link to https://www.example.com/user/@mouse"
+ mentions = views.status.find_mentions(self.local_user, content)
+ # pylint: disable=line-too-long
+ self.assertEqual(
+ views.status.format_mentions(content, mentions),
+ 'a link to www.example.com/user/@mouse'
+ )
+
def test_to_markdown(self, *_):
"""this is mostly handled in other places, but nonetheless"""
text = "_hi_ and http://fish.com is "
diff --git a/bookwyrm/views/status.py b/bookwyrm/views/status.py
index 82d033d7c..866657a3b 100644
--- a/bookwyrm/views/status.py
+++ b/bookwyrm/views/status.py
@@ -96,18 +96,12 @@ class CreateStatus(View):
# inspect the text for user tags
content = status.content
- for (mention_text, mention_user) in find_mentions(
- request.user, content
- ).items():
+ mentions = find_mentions(request.user, content)
+ for (_, mention_user) in mentions:
# add them to status mentions fk
status.mention_users.add(mention_user)
+ content = format_mentions(content, mentions)
- # turn the mention into a link
- content = re.sub(
- rf"{mention_text}\b(?!@)",
- rf'{mention_text}',
- content,
- )
# add reply parent to mentions
if status.reply_parent:
status.mention_users.add(status.reply_parent.user)
@@ -149,6 +143,17 @@ class CreateStatus(View):
return HttpResponse()
return redirect_to_referer(request)
+def format_mentions(content, mentions):
+ """Detect @mentions and make them links"""
+ for (mention_text, mention_user) in mentions.items():
+ # turn the mention into a link
+ content = re.sub(
+ rf"{mention_text}\b(?!@)",
+ rf'{mention_text}',
+ content,
+ )
+ return content
+
@method_decorator(login_required, name="dispatch")
class DeleteStatus(View):