[backend] Only render trailing slashes for URLs in profile fields when explicitly specified

This commit is contained in:
Laura Hausmann 2023-10-12 16:58:54 +02:00
parent 9167ba593c
commit f843453ca0
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -35,16 +35,17 @@ export async function renderPerson(user: ILocalUser) {
if (profile.fields) { if (profile.fields) {
for (const field of 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 = `<a href="${field.value}" rel="me nofollow noopener" target="_blank">${field.value}</a>`;
}
attachment.push({ attachment.push({
type: "PropertyValue", type: "PropertyValue",
name: field.name, name: field.name,
value: field.value?.match(/^https?:/) value: field.value,
? `<a href="${
new URL(field.value).href
}" rel="me nofollow noopener" target="_blank">${
new URL(field.value).href
}</a>`
: field.value,
}); });
} }
} }