mirror of
https://github.com/jointakahe/takahe.git
synced 2024-12-25 23:00:29 +00:00
Guard Post mentions processing from unfetched Identities (#272)
This commit is contained in:
parent
d2766860c5
commit
50c07f491e
2 changed files with 24 additions and 9 deletions
|
@ -139,8 +139,11 @@ class ContentRenderer:
|
|||
url = str(mention.urls.view)
|
||||
else:
|
||||
url = mention.absolute_profile_uri()
|
||||
possible_matches[mention.username.lower()] = url
|
||||
possible_matches[f"{mention.username.lower()}@{mention.domain_id}"] = url
|
||||
# Might not have fetched it (yet)
|
||||
if mention.username:
|
||||
username = mention.username.lower()
|
||||
possible_matches[username] = url
|
||||
possible_matches[f"{username}@{mention.domain_id}"] = url
|
||||
|
||||
collapse_name: dict[str, str] = {}
|
||||
|
||||
|
|
|
@ -75,15 +75,27 @@ def test_link_mixcase_mentions():
|
|||
fake_mention2.username = "manfre"
|
||||
fake_mention2.domain_id = "takahe.social"
|
||||
fake_mention2.urls.view = "https://takahe.social/@manfre@takahe.social/"
|
||||
|
||||
unfetched_mention = Mock()
|
||||
unfetched_mention.username = None
|
||||
unfetched_mention.domain_id = None
|
||||
unfetched_mention.urls.view = "/None@None/"
|
||||
|
||||
fake_post = Mock()
|
||||
fake_post.mentions.all.return_value = [fake_mention, fake_mention2]
|
||||
fake_post.mentions.all.return_value = [
|
||||
fake_mention,
|
||||
fake_mention2,
|
||||
unfetched_mention,
|
||||
]
|
||||
fake_post.author.domain.uri_domain = "example.com"
|
||||
fake_post.emojis.all.return_value = []
|
||||
|
||||
assert (
|
||||
renderer.render_post(
|
||||
"@Manfre@manfre.net @mAnFrE@takahe.social @manfre@manfre.net",
|
||||
fake_post,
|
||||
)
|
||||
== '<a href="/@Manfre@manfre.net/">@Manfre</a> <a href="https://takahe.social/@manfre@takahe.social/">@mAnFrE@takahe.social</a> <a href="/@Manfre@manfre.net/">@manfre</a>'
|
||||
assert renderer.render_post(
|
||||
"@Manfre@manfre.net @mAnFrE@takahe.social @manfre@manfre.net @unfetched@manfre.net",
|
||||
fake_post,
|
||||
) == (
|
||||
'<a href="/@Manfre@manfre.net/">@Manfre</a> '
|
||||
'<a href="https://takahe.social/@manfre@takahe.social/">@mAnFrE@takahe.social</a> '
|
||||
'<a href="/@Manfre@manfre.net/">@manfre</a> '
|
||||
"@unfetched@manfre.net"
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue