From 6202cf6b65fe8351114e87bee08af2fe3829de2a Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 4 Aug 2025 09:49:12 +0200 Subject: [PATCH] Fix WebUI crashing for accounts with `null` URL (#35651) --- app/javascript/mastodon/api_types/accounts.ts | 2 +- app/javascript/mastodon/models/account.ts | 7 ++++--- app/serializers/rest/account_serializer.rb | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/javascript/mastodon/api_types/accounts.ts b/app/javascript/mastodon/api_types/accounts.ts index fdbd7523fc..4e5dd1a692 100644 --- a/app/javascript/mastodon/api_types/accounts.ts +++ b/app/javascript/mastodon/api_types/accounts.ts @@ -37,7 +37,7 @@ export interface BaseApiAccountJSON { roles?: ApiAccountJSON[]; statuses_count: number; uri: string; - url: string; + url?: string; username: string; moved?: ApiAccountJSON; suspended?: boolean; diff --git a/app/javascript/mastodon/models/account.ts b/app/javascript/mastodon/models/account.ts index 4c89a0c30d..1c6eadce1b 100644 --- a/app/javascript/mastodon/models/account.ts +++ b/app/javascript/mastodon/models/account.ts @@ -46,7 +46,7 @@ const AccountRoleFactory = ImmutableRecord({ // Account export interface AccountShape extends Required< - Omit + Omit > { emojis: List; fields: List; @@ -56,6 +56,7 @@ export interface AccountShape note_plain: string | null; hidden: boolean; moved: string | null; + url: string; } export type Account = RecordOf; @@ -151,8 +152,8 @@ export function createAccountFromServerJSON(serverJSON: ApiAccountJSON) { note_emojified: emojify(accountJSON.note, emojiMap), note_plain: unescapeHTML(accountJSON.note), url: - accountJSON.url.startsWith('http://') || - accountJSON.url.startsWith('https://') + accountJSON.url?.startsWith('http://') || + accountJSON.url?.startsWith('https://') ? accountJSON.url : accountJSON.uri, }); diff --git a/app/serializers/rest/account_serializer.rb b/app/serializers/rest/account_serializer.rb index 354d384464..b102f79fdb 100644 --- a/app/serializers/rest/account_serializer.rb +++ b/app/serializers/rest/account_serializer.rb @@ -65,7 +65,7 @@ class REST::AccountSerializer < ActiveModel::Serializer end def url - ActivityPub::TagManager.instance.url_for(object) + ActivityPub::TagManager.instance.url_for(object) || ActivityPub::TagManager.instance.uri_for(object) end def uri