From 6cb57c472cea0fd5f9727fc19a1b1f5674f9b313 Mon Sep 17 00:00:00 2001 From: "Arvind Yadav." <82073257+Arvind0302@users.noreply.github.com> Date: Wed, 29 Oct 2025 03:18:16 +0530 Subject: [PATCH] feat(avatar): Strip bracketed annotations from display names before generating initials Fixes #16591. --- react/features/base/avatar/functions.ts | 32 ++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/react/features/base/avatar/functions.ts b/react/features/base/avatar/functions.ts index cb2a6b398d..0e9ee3bb9f 100644 --- a/react/features/base/avatar/functions.ts +++ b/react/features/base/avatar/functions.ts @@ -55,6 +55,28 @@ function getFirstGraphemeUpper(word: string) { return splitter.splitGraphemes(word)[0].toUpperCase(); } +/** + * Strips bracketed annotations from a display name. Handles multiple bracket types like (), + * [], and {}. + * + * @param {string} name - The display name to clean. + * @returns {string} The cleaned display name without bracketed annotations. + */ +function stripBracketedAnnotations(name: string): string { + // Match content within any of the bracket types at the end of the string + // This regex matches: (...) or [...] or {...} at the end + const bracketRegex = /\s*[([{][^)\]}]*[)\]}]$/; + + let cleaned = name; + + // Remove all trailing bracketed annotations (handle multiple occurrences) + while (bracketRegex.test(cleaned)) { + cleaned = cleaned.replace(bracketRegex, ''); + } + + return cleaned.trim(); +} + /** * Generates initials for a simple string. * @@ -64,7 +86,15 @@ function getFirstGraphemeUpper(word: string) { export function getInitials(s?: string) { // We don't want to use the domain part of an email address, if it is one const initialsBasis = split(s, '@')[0]; - const [ firstWord, ...remainingWords ] = initialsBasis.split(wordSplitRegex).filter(Boolean); + + // Strip bracketed annotations (e.g., "(Department)", "[Team]", "{Org}") + // to prevent them from being considered as name parts + const cleanedName = stripBracketedAnnotations(initialsBasis); + + // Fallback to original if cleaned name is empty + const nameForInitials = cleanedName || initialsBasis; + + const [ firstWord, ...remainingWords ] = nameForInitials.split(wordSplitRegex).filter(Boolean); return getFirstGraphemeUpper(firstWord) + getFirstGraphemeUpper(remainingWords.pop() || ''); }