瀏覽代碼

fix: don't allow blank space in collab name (#6211)

* don't allow blank space in collab name

* add spec

* prevent blank
Aakansha Doshi 2 年之前
父節點
當前提交
c9d18ecab6
共有 3 個文件被更改,包括 7 次插入2 次删除
  1. 1 1
      src/clients.ts
  2. 1 1
      src/excalidraw-app/collab/RoomDialog.tsx
  3. 5 0
      src/tests/clients.test.ts

+ 1 - 1
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();

+ 1 - 1
src/excalidraw-app/collab/RoomDialog.tsx

@@ -144,7 +144,7 @@ const RoomDialog = ({
               <input
                 type="text"
                 id="username"
-                value={username || ""}
+                value={username.trim() || ""}
                 className="RoomDialog-username TextInput"
                 onChange={(event) => onUsernameChange(event.target.value)}
                 onKeyPress={(event) => event.key === "Enter" && handleClose()}

+ 5 - 0
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("?");
+  });
 });