Don't allow trailing period in mention

Fixes #249
This commit is contained in:
Andrew Godwin 2022-12-23 01:46:35 -07:00
parent c969ffc0d6
commit 294095c592
2 changed files with 14 additions and 1 deletions

View File

@ -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:

View File

@ -77,6 +77,7 @@ def test_linkify_mentions_remote(
local=True,
)
assert post.safe_content_remote() == "<p>@test@example.com, welcome!</p>"
# Test case insensitivity (remote)
post = Post.objects.create(
content="<p>Hey @TeSt</p>",
@ -89,6 +90,18 @@ def test_linkify_mentions_remote(
== '<p>Hey <a href="https://remote.test/@test/">@test</a></p>'
)
# Test trailing dot (remote)
post = Post.objects.create(
content="<p>Hey @test@remote.test.</p>",
author=identity,
local=True,
)
post.mentions.add(remote_identity)
assert (
post.safe_content_remote()
== '<p>Hey <a href="https://remote.test/@test/">@test</a>.</p>'
)
# Test that collapsing only applies to the first unique, short username
post = Post.objects.create(
content="<p>Hey @TeSt@remote.test and @test@remote2.test</p>",