diff --git a/web/src/people.ts b/web/src/people.ts index b7c18f425a..73a7adf294 100644 --- a/web/src/people.ts +++ b/web/src/people.ts @@ -653,6 +653,10 @@ export function pm_perma_link(message: Message): string | undefined { return url; } +export function get_slug_from_full_name(full_name: string): string { + return full_name.replaceAll(/[ "%/<>`\p{C}]+/gu, "-"); +} + export function pm_with_url(message: Message | MessageWithBooleans): string | undefined { const user_ids = pm_with_user_ids(message); @@ -667,7 +671,7 @@ export function pm_with_url(message: Message | MessageWithBooleans): string | un } else { const person = maybe_get_user_by_id(user_ids[0]); if (person?.full_name) { - suffix = person.full_name.replaceAll(/[ "%/<>`\p{C}]+/gu, "-"); + suffix = get_slug_from_full_name(person.full_name); } else { blueslip.error("Unknown people in message"); suffix = "unk"; @@ -759,8 +763,7 @@ export function emails_to_slug(emails_string: string): string | undefined { if (emails.length === 1 && emails[0] !== undefined) { const person = get_by_email(emails[0]); assert(person !== undefined, "Unknown person in emails_to_slug"); - const name = person.full_name; - slug += name.replaceAll(/[ "%/<>`\p{C}]+/gu, "-"); + slug += get_slug_from_full_name(person.full_name); } else { slug += "group"; }