[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
Signed by: zotan
GPG key ID: D044E84C5BE01605

View file

@ -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 = `<a href="${field.value}" rel="me nofollow noopener" target="_blank">${field.value}</a>`;
}
attachment.push({
type: "PropertyValue",
name: field.name,
value: field.value?.match(/^https?:/)
? `<a href="${
new URL(field.value).href
}" rel="me nofollow noopener" target="_blank">${
new URL(field.value).href
}</a>`
: field.value,
value: field.value,
});
}
}