From b73031be9b5e7131228e628cf21bd4d7bbfdccb6 Mon Sep 17 00:00:00 2001 From: mektpoy Date: Tue, 22 Sep 2026 20:27:45 +0800 Subject: [PATCH] test(native-command): pin the Explorer target for verbatim and device paths A verbatim `\\?\` prefix and a `\\.\` device namespace take Node's UNC resolution, and the comma encoding has to survive them. The drive-root case is pinned separately because Node restores a trailing separator against the host's `path.sep`, which differs on the Windows host this opener runs on. --- .../native-command/tests/path-opener.spec.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/packages/util/native-command/tests/path-opener.spec.ts b/packages/util/native-command/tests/path-opener.spec.ts index 97167872ed..d4996539f2 100644 --- a/packages/util/native-command/tests/path-opener.spec.ts +++ b/packages/util/native-command/tests/path-opener.spec.ts @@ -91,12 +91,33 @@ describe('native path opener', () => { ['C:\\work\\my report.txt', 'file:///C:/work/my%20report.txt'], ['C:\\my files\\报告,#%.txt', 'file:///C:/my%20files/%E6%8A%A5%E5%91%8A%2C%23%25.txt'], ['\\\\server\\share\\a,b.txt', 'file://server/share/a%2Cb.txt'], + // Node resolves the path before encoding it, so a verbatim prefix is not + // part of the target: `\\?\` and `\\?\UNC\` arrive as the ordinary drive or + // UNC URI. A device-namespace path takes that same UNC handling; it names a + // device rather than a shell item, which this opener does not open. + ['\\\\?\\C:\\work\\a,b.txt', 'file:///C:/work/a%2Cb.txt'], + ['\\\\?\\UNC\\server\\share\\a,b.txt', 'file://server/share/a%2Cb.txt'], + ['\\\\.\\C:\\work\\a,b.txt', 'file://./C:/work/a%2Cb.txt'], + ['\\\\wsl$\\Ubuntu\\home\\t,est a.txt', 'file://wsl$/Ubuntu/home/t%2Cest%20a.txt'], ] as const)('opens %s through the one encoded Explorer target', async (path, target) => { const run = vi.fn(async () => ({ stdout: '', stderr: '' })) await openNativePath(path, signal(), { platform: 'win32', run }) expect(run).toHaveBeenCalledExactlyOnceWith('explorer.exe', [target], expect.any(AbortSignal)) }) + // Node restores a trailing separator against the host's `path.sep`, so a + // separator-terminated Windows path encodes differently on the Windows host + // this opener runs on than on the POSIX host a test run may use. + it('encodes a separator-terminated drive root as the hosting platform resolves it', async () => { + const run = vi.fn(async () => ({ stdout: '', stderr: '' })) + await openNativePath('C:\\', signal(), { platform: 'win32', run }) + expect(run).toHaveBeenCalledExactlyOnceWith( + 'explorer.exe', + [process.platform === 'win32' ? 'file:///C:/' : 'file:///C://'], + expect.any(AbortSignal), + ) + }) + it('encodes a directory target the same way it encodes a file target', async () => { const run = vi.fn(async () => ({ stdout: '', stderr: '' })) await openNativeAssociatedPath('C:\\work\\dir,comma', signal(), { platform: 'win32', run })