server: fix error for invalid URLs in profile fields
ci/woodpecker/push/lint-foundkey-js Pipeline was successful Details
ci/woodpecker/push/lint-client Pipeline was successful Details
ci/woodpecker/push/lint-backend Pipeline was successful Details
ci/woodpecker/push/build Pipeline was successful Details
ci/woodpecker/push/lint-sw Pipeline was successful Details
ci/woodpecker/push/test Pipeline was successful Details

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: Johann150
GPG Key ID: 9EE6577A2A06F8F1
1 changed files with 12 additions and 3 deletions

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,
});
}
}