From 75b6cddb04db88fddf9e6272d55801ecc5a3bee8 Mon Sep 17 00:00:00 2001
From: Lim Chee Aun <cheeaun@gmail.com>
Date: Wed, 15 Feb 2023 21:40:58 +0800
Subject: [PATCH] Fix conditions not scoped properly

---
 src/components/name-text.jsx | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/components/name-text.jsx b/src/components/name-text.jsx
index 8367446e..0137f500 100644
--- a/src/components/name-text.jsx
+++ b/src/components/name-text.jsx
@@ -21,14 +21,15 @@ function NameText({
 
   const trimmedUsername = username.toLowerCase().trim();
   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
 
   if (
-    (!short && trimmedUsername === trimmedDisplayName) ||
-    trimmedUsername ===
-      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
+    !short &&
+    (trimmedUsername === trimmedDisplayName ||
+      trimmedUsername === shortenedDisplayName)
   ) {
     username = null;
   }