From f843453ca0641d2f7065b4fbb3041b1ca6b26026 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Thu, 12 Oct 2023 16:58:54 +0200 Subject: [PATCH] [backend] Only render trailing slashes for URLs in profile fields when explicitly specified --- .../src/remote/activitypub/renderer/person.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/remote/activitypub/renderer/person.ts b/packages/backend/src/remote/activitypub/renderer/person.ts index 1122a3a27..7905653a2 100644 --- a/packages/backend/src/remote/activitypub/renderer/person.ts +++ b/packages/backend/src/remote/activitypub/renderer/person.ts @@ -35,16 +35,17 @@ export async function renderPerson(user: ILocalUser) { if (profile.fields) { for (const field of profile.fields) { + if (field.value?.match(/^https?:\/\//)) { + const hasTrailingSlash = field.value.endsWith('/'); + field.value = new URL(field.value).href; + if (field.value.endsWith('/') && !hasTrailingSlash) field.value = field.value.slice(0, -1); + field.value = `${field.value}`; + } + attachment.push({ type: "PropertyValue", name: field.name, - value: field.value?.match(/^https?:/) - ? `${ - new URL(field.value).href - }` - : field.value, + value: field.value, }); } }