From ce67f794d24ca90c22e05ee5fc7d466646a5761e Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Sat, 9 May 2026 00:27:41 -0700 Subject: [PATCH] fix(worktree): allow Unicode letters/numbers in workspace names (#1624) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Users typing CJK or other non-ASCII names (e.g. 中文) into the Create Workspace dialog hit "Invalid worktree name" because the sanitizer's ASCII-only allowlist stripped every character, leaving an empty string. Replace the allowlist with a Unicode-aware one (\p{L}\p{N}) so non-Latin scripts pass through. Git ref-format and modern filesystems accept UTF-8. Co-authored-by: Orca --- src/main/ipc/worktree-logic.test.ts | 14 ++++++++++++++ src/main/ipc/worktree-logic.ts | 8 +++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/ipc/worktree-logic.test.ts b/src/main/ipc/worktree-logic.test.ts index 4b6b8e390..099753bed 100644 --- a/src/main/ipc/worktree-logic.test.ts +++ b/src/main/ipc/worktree-logic.test.ts @@ -51,6 +51,20 @@ describe('sanitizeWorktreeName', () => { expect(sanitizeWorktreeName('a..b...c')).toBe('a.b.c') }) + it('preserves non-ASCII letters and numbers', () => { + // Why: users name workspaces in their own language (CJK, accented Latin, + // Cyrillic, etc.). Stripping these to ASCII left the name empty and threw + // "Invalid worktree name" on every non-Latin keyboard input. + expect(sanitizeWorktreeName('中文')).toBe('中文') + expect(sanitizeWorktreeName('日本語 テスト')).toBe('日本語-テスト') + expect(sanitizeWorktreeName('café-déjà')).toBe('café-déjà') + expect(sanitizeWorktreeName('Привет мир')).toBe('Привет-мир') + }) + + it('still strips git-unsafe punctuation around Unicode names', () => { + expect(sanitizeWorktreeName('feat: 中文 (v2)')).toBe('feat-中文-v2') + }) + it('throws for empty name', () => { expect(() => sanitizeWorktreeName('')).toThrow('Invalid worktree name') }) diff --git a/src/main/ipc/worktree-logic.ts b/src/main/ipc/worktree-logic.ts index a69035f42..b3fa2755f 100644 --- a/src/main/ipc/worktree-logic.ts +++ b/src/main/ipc/worktree-logic.ts @@ -7,11 +7,13 @@ import { getWslHome, parseWslPath } from '../wsl' * Strips unsafe characters and collapses runs of special chars to a single hyphen. */ export function sanitizeWorktreeName(input: string): string { + // Why: keep Unicode letters/numbers (CJK, accented Latin, etc.) so users can + // name workspaces in their own language. Git ref-format permits non-ASCII + // bytes, and modern filesystems handle UTF-8 paths. Only strip characters + // git or the filesystem actually rejects. const sanitized = input .trim() - .replace(/[\\/]+/g, '-') - .replace(/\s+/g, '-') - .replace(/[^A-Za-z0-9._-]+/g, '-') + .replace(/[^\p{L}\p{N}._-]+/gu, '-') .replace(/-+/g, '-') // Why: git check-ref-format rejects any ref containing `..`, so a prompt // like "../../foo" that survives slugification as `..-..-foo` would