Skip to content

Commit 614fd12

Browse files
committed
fix(profile): strip the @ from Bluesky profile links
Bluesky handles are stored @-prefixed (the form prepends @ on save), and the profile partial interpolated the stored value straight into the href, producing bsky.app/profile/@handle — which does not resolve. The href now cuts the @ so the link lands on bsky.app/profile/handle for both @-prefixed and legacy bare stored values, and the visible label consistently displays @handle either way. Storage and the form's existing clean behaviour are unchanged. (cherry picked from commit 2113ff6)
1 parent a542a23 commit 614fd12

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

knowledge_commons_profiles/newprofile/tests/test_social_media_at_prefix.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,34 @@ def test_bluesky_without_at_unchanged_in_initial(self):
219219
)
220220
form = ProfileForm(instance=profile)
221221
self.assertEqual(form.initial["bluesky"], "user.bsky.social")
222+
223+
224+
class BlueskyLinkRenderingTests(TestCase):
225+
"""The Bluesky profile link must never contain the stored @.
226+
227+
bsky.app/profile/@handle does not resolve; the href needs the bare
228+
handle whether the stored value is @-prefixed (the canonical saved
229+
form) or bare (legacy rows saved before the @ was prepended).
230+
"""
231+
232+
def _render(self, bluesky_value):
233+
from django.template.loader import render_to_string
234+
235+
return render_to_string(
236+
"newprofile/partials/profile_info.html",
237+
{"profile_info": {"bluesky": bluesky_value}},
238+
)
239+
240+
def test_bluesky_href_strips_stored_at(self):
241+
html = self._render("@eve.gd")
242+
self.assertIn('href="https://bsky.app/profile/eve.gd"', html)
243+
self.assertNotIn("profile/@eve.gd", html)
244+
245+
def test_bluesky_href_with_bare_handle(self):
246+
html = self._render("eve.gd")
247+
self.assertIn('href="https://bsky.app/profile/eve.gd"', html)
248+
249+
def test_bluesky_label_always_displays_at_prefix(self):
250+
for stored in ("@eve.gd", "eve.gd"):
251+
html = self._render(stored)
252+
self.assertIn("<span>@eve.gd</span>", html)

knowledge_commons_profiles/templates/newprofile/partials/profile_info.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@
3434

3535
<!-- Bluesky -->
3636
{% if profile_info.bluesky %}
37-
<a href="https://bsky.app/profile/{{ profile_info.bluesky }}"
37+
{# the stored handle may carry a leading @, which bsky.app profile URLs do not resolve #}
38+
<a href="https://bsky.app/profile/{{ profile_info.bluesky|cut:"@" }}"
3839
class="social-link" id="bluesky" aria-label="Bluesky" hx-swap-oob="true">
3940
<img class="bluesky" src="{% static "img/bluesky.png" %}" alt="bluesky" />
40-
<span>{{ profile_info.bluesky }}</span>
41+
<span>@{{ profile_info.bluesky|cut:"@" }}</span>
4142
</a>
4243
{% else %}
4344
<a href="#" class="hide" id="bluesky" aria-label="Bluesky" aria-hidden="true" hx-swap-oob="true"></a>

0 commit comments

Comments
 (0)