diff --git a/core/html.py b/core/html.py
index 3c48df4..c413cf4 100644
--- a/core/html.py
+++ b/core/html.py
@@ -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] = {}
diff --git a/tests/core/test_html.py b/tests/core/test_html.py
index 5589105..fe7b098 100644
--- a/tests/core/test_html.py
+++ b/tests/core/test_html.py
@@ -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,
- )
- == '@Manfre @mAnFrE@takahe.social @manfre'
+ assert renderer.render_post(
+ "@Manfre@manfre.net @mAnFrE@takahe.social @manfre@manfre.net @unfetched@manfre.net",
+ fake_post,
+ ) == (
+ '@Manfre '
+ '@mAnFrE@takahe.social '
+ '@manfre '
+ "@unfetched@manfre.net"
)