Skip to content

Commit 8ccda10

Browse files
fix(server): reveal normalized paths in File Explorer
1 parent f54ab90 commit 8ccda10

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

‎apps/server/src/process/externalLauncher.test.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ it.effect("reveals a file in File Explorer through PowerShell on Windows", () =>
206206
const launcher = yield* ExternalLauncher.ExternalLauncher;
207207
yield* launcher.launchEditor({
208208
editor: "file-manager",
209-
cwd: "C:\\workspace with spaces\\media\\author's clip.mp4",
209+
// Web file links normalize separators even when the server runs on
210+
// Windows. Explorer's `/select` switch requires Windows separators.
211+
cwd: "C:/workspace with spaces/media/author's clip.mp4",
210212
reveal: true,
211213
});
212214
return yield* launcher.resolveFileManagerRevealKind();
@@ -261,8 +263,12 @@ it.skipIf(process.platform !== "win32")(
261263
const outputPath = NodePath.join(tempDir, "argv.txt");
262264
NodeFS.writeFileSync(recorderPath, `@echo off\r\n>"${outputPath}" echo(%*\r\n`);
263265

264-
const target = "C:\\workspace with spaces\\media\\author's clip.mp4";
265-
const source = ExternalLauncher.buildFileExplorerRevealPowerShellSource(recorderPath, target);
266+
const target = "C:/workspace with spaces/media/author's clip.mp4";
267+
const explorerTarget = target.replaceAll("/", "\\");
268+
const source = ExternalLauncher.buildFileExplorerRevealPowerShellSource(
269+
recorderPath,
270+
explorerTarget,
271+
);
266272
const powerShellPath = `${process.env.SYSTEMROOT ?? "C:\\Windows"}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
267273
NodeChildProcess.execFileSync(
268274
powerShellPath,
@@ -290,7 +296,7 @@ it.skipIf(process.platform !== "win32")(
290296
}
291297
await sleep(200);
292298
const recorded = NodeFS.readFileSync(outputPath, "utf8").trim();
293-
assert.equal(recorded, `/select,"${target}"`);
299+
assert.equal(recorded, `/select,"${explorerTarget}"`);
294300
} finally {
295301
NodeFS.rmSync(tempDir, { recursive: true, force: true });
296302
}

‎apps/server/src/process/externalLauncher.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,10 @@ function fileExplorerRevealLaunch(
609609
};
610610
}
611611

612+
function normalizeWindowsFileManagerPath(target: string): string {
613+
return target.replaceAll("/", "\\");
614+
}
615+
612616
const resolveFileManagerRevealLaunch = Effect.fn("resolveFileManagerRevealLaunch")(function* (
613617
target: string,
614618
platform: NodeJS.Platform,
@@ -626,7 +630,11 @@ const resolveFileManagerRevealLaunch = Effect.fn("resolveFileManagerRevealLaunch
626630
}
627631

628632
if (platform === "win32") {
629-
return fileExplorerRevealLaunch(target, target, resolvePowerShellPath(env));
633+
return fileExplorerRevealLaunch(
634+
target,
635+
normalizeWindowsFileManagerPath(target),
636+
resolvePowerShellPath(env),
637+
);
630638
}
631639

632640
if (

0 commit comments

Comments
 (0)