server: fix error for invalid URLs in profile fields

Co-authored-by: Chloe Kudryavtsev <code@code.bunkerlabs.net>
This commit is contained in:
Johann150 2023-01-30 19:23:12 +01:00
parent bb3ec8bafe
commit 2d32bc33d7
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1

View file

@ -30,12 +30,21 @@ export async function renderPerson(user: ILocalUser) {
if (profile.fields) {
for (const field of profile.fields) {
let value = field.value;
// try to parse it as a url
try {
if (field.value?.match(/^https?:/)) {
const url = new URL(field.value);
value = `<a href="${url.href}" rel="me nofollow noopener" target="_blank">${url.href}</a>`;
}
} catch {
// guess it wasn't a url after all...
}
attachment.push({
type: 'PropertyValue',
name: field.name,
value: (field.value != null && 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,
});
}
}