From ac02598150f2987c56faad25bf985b316cc49d29 Mon Sep 17 00:00:00 2001 From: yangkun Date: Wed, 2 Sep 2026 10:22:34 +0800 Subject: [PATCH] fix: preserve Windows explorer reveal selection --- src/open-external.ts | 7 +++---- tests/open-external.spec.ts | 7 +++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/open-external.ts b/src/open-external.ts index de0fabf..6a1ef67 100644 --- a/src/open-external.ts +++ b/src/open-external.ts @@ -28,11 +28,10 @@ export function revealCommand(path: string, platform: NodeJS.Platform = process. switch (platform) { case 'darwin': return { command: 'open', args: ['-R', path] } - // `explorer /select,` — the classic "show in folder" incantation. - // Passed as separate argv entries (no shell); verify on Windows, with - // `cmd /c start "" explorer.exe "/select,"` as the fallback. + // Explorer expects `/select,` as one argument. Keep the spawn + // shell-free: a command shell would reinterpret valid path characters. case 'win32': - return { command: 'explorer.exe', args: ['/select,', path] } + return { command: 'explorer.exe', args: [`/select,${path}`] } default: { const parent = parentOf(path) return { command: 'xdg-open', args: [parent ?? path] } diff --git a/tests/open-external.spec.ts b/tests/open-external.spec.ts index 6585930..d83477c 100644 --- a/tests/open-external.spec.ts +++ b/tests/open-external.spec.ts @@ -13,8 +13,11 @@ describe('revealCommand', () => { expect(revealCommand('/a/b.txt', 'darwin')).toEqual({ command: 'open', args: ['-R', '/a/b.txt'] }) }) - it('win32: `explorer /select,` selects the file', () => { - expect(revealCommand('C:\\a\\b.txt', 'win32')).toEqual({ command: 'explorer.exe', args: ['/select,', 'C:\\a\\b.txt'] }) + it('win32: passes /select, as one shell-free Explorer argument', () => { + expect(revealCommand('C:\\work\\two words\\a.txt', 'win32')).toEqual({ + command: 'explorer.exe', + args: ['/select,C:\\work\\two words\\a.txt'], + }) }) it('linux: `xdg-open` opens the containing directory (no common select protocol)', () => {