mirror of
https://github.com/jointakahe/takahe.git
synced 2024-12-23 05:56:29 +00:00
parent
9fe2e6676c
commit
5b82c76def
2 changed files with 8 additions and 7 deletions
|
@ -279,8 +279,12 @@ class Post(StatorModel):
|
|||
def replacer(match):
|
||||
precursor = match.group(1)
|
||||
handle = match.group(2).lower()
|
||||
if "@" in handle:
|
||||
short_handle = handle.split("@", 1)[0]
|
||||
else:
|
||||
short_handle = handle
|
||||
if handle in possible_matches:
|
||||
return f'{precursor}<a href="{possible_matches[handle]}">@{handle}</a>'
|
||||
return f'{precursor}<a href="{possible_matches[handle]}">@{short_handle}</a>'
|
||||
else:
|
||||
return match.group()
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ def test_linkify_mentions_remote(identity, remote_identity):
|
|||
post.mentions.add(identity)
|
||||
assert (
|
||||
post.safe_content_remote()
|
||||
== '<p><a href="https://example.com/@test/">@test@example.com</a>, welcome!</p>'
|
||||
== '<p><a href="https://example.com/@test/">@test</a>, welcome!</p>'
|
||||
)
|
||||
# Test that they don't get touched without a mention
|
||||
post = Post.objects.create(
|
||||
|
@ -103,7 +103,7 @@ def test_linkify_mentions_local(identity, remote_identity):
|
|||
post.mentions.add(identity)
|
||||
assert (
|
||||
post.safe_content_local()
|
||||
== '<p><a href="/@test@example.com/">@test@example.com</a>, welcome!</p>'
|
||||
== '<p><a href="/@test@example.com/">@test</a>, welcome!</p>'
|
||||
)
|
||||
# Test a full username (remote) with no <p>
|
||||
post = Post.objects.create(
|
||||
|
@ -112,10 +112,7 @@ def test_linkify_mentions_local(identity, remote_identity):
|
|||
local=True,
|
||||
)
|
||||
post.mentions.add(remote_identity)
|
||||
assert (
|
||||
post.safe_content_local()
|
||||
== '<a href="/@test@remote.test/">@test@remote.test</a> hello!'
|
||||
)
|
||||
assert post.safe_content_local() == '<a href="/@test@remote.test/">@test</a> hello!'
|
||||
# Test that they don't get touched without a mention
|
||||
post = Post.objects.create(
|
||||
content="<p>@test@example.com, welcome!</p>",
|
||||
|
|
Loading…
Reference in a new issue