From ddd1ec5819bc185f3549b39be762000c72166f16 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Wed, 4 Oct 2023 21:23:21 +0800 Subject: [PATCH] Compare accents and diacritics too --- src/components/name-text.jsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/name-text.jsx b/src/components/name-text.jsx index b1b8952b..3374063b 100644 --- a/src/components/name-text.jsx +++ b/src/components/name-text.jsx @@ -25,13 +25,20 @@ function NameText({ const trimmedDisplayName = (displayName || '').toLowerCase().trim(); const shortenedDisplayName = trimmedDisplayName .replace(/(\:(\w|\+|\-)+\:)(?=|[\!\.\?]|$)/g, '') // Remove shortcodes, regex from https://regex101.com/r/iE9uV0/1 - .replace(/\s+/g, '') // E.g. "My name" === "myname" - .replace(/[^a-z0-9]/gi, ''); // Remove non-alphanumeric characters + .replace(/\s+/g, ''); // E.g. "My name" === "myname" + const shortenedAlphaNumericDisplayName = shortenedDisplayName.replace( + /[^a-z0-9]/gi, + '', + ); // Remove non-alphanumeric characters if ( !short && (trimmedUsername === trimmedDisplayName || - trimmedUsername === shortenedDisplayName) + trimmedUsername === shortenedDisplayName || + trimmedUsername === shortenedAlphaNumericDisplayName || + trimmedUsername.localeCompare?.(shortenedDisplayName, 'en', { + sensitivity: 'base', + }) === 0) ) { username = null; }