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