From c9d18ecab685a8c1f52eba43a2d53314c339e6a2 Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Thu, 9 Feb 2023 15:51:49 +0530 Subject: [PATCH] fix: don't allow blank space in collab name (#6211) * don't allow blank space in collab name * add spec * prevent blank --- src/clients.ts | 2 +- src/excalidraw-app/collab/RoomDialog.tsx | 2 +- src/tests/clients.test.ts | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/clients.ts b/src/clients.ts index e31b73eb..9e1e6e14 100644 --- a/src/clients.ts +++ b/src/clients.ts @@ -21,7 +21,7 @@ export const getClientColors = (clientId: string, appState: AppState) => { }; export const getClientInitials = (userName?: string | null) => { - if (!userName) { + if (!userName?.trim()) { return "?"; } return userName.trim()[0].toUpperCase(); diff --git a/src/excalidraw-app/collab/RoomDialog.tsx b/src/excalidraw-app/collab/RoomDialog.tsx index d4adf977..2c6949aa 100644 --- a/src/excalidraw-app/collab/RoomDialog.tsx +++ b/src/excalidraw-app/collab/RoomDialog.tsx @@ -144,7 +144,7 @@ const RoomDialog = ({ onUsernameChange(event.target.value)} onKeyPress={(event) => event.key === "Enter" && handleClose()} diff --git a/src/tests/clients.test.ts b/src/tests/clients.test.ts index f3fd174b..a6a6901b 100644 --- a/src/tests/clients.test.ts +++ b/src/tests/clients.test.ts @@ -36,4 +36,9 @@ describe("getClientInitials", () => { result = getClientInitials(null); expect(result).toBe("?"); }); + + it('returns "?" when value is blank', () => { + const result = getClientInitials(" "); + expect(result).toBe("?"); + }); });