diff --git a/packages/cli/src/utils/checkBrowser.test.ts b/packages/cli/src/utils/checkBrowser.test.ts index 0af1041803..c59c7b82ba 100644 --- a/packages/cli/src/utils/checkBrowser.test.ts +++ b/packages/cli/src/utils/checkBrowser.test.ts @@ -2554,6 +2554,34 @@ describe("finding frame capture", () => { } }); + // fails without the fix: the name was decoded twice, so these files got no copy window + it("keeps the copy window of a video whose name has #, ? or %", async () => { + const dir = mkdtempSync(join(tmpdir(), "finding-windows-names-")); + // Windows refuses ? in a file name. + const names = [ + "clip #1.mov", + "50% off.mov", + ...(process.platform === "win32" ? [] : ["a?b.mov"]), + ]; + for (const name of names) writeFileSync(join(dir, name), ""); + installSessionMock(fakePage()); + mocks.bundleWithLocalizedFonts.mockResolvedValueOnce( + `${names.map((name) => ``).join("")}`, + ); + mocks.proxyWindowSeconds.mockClear(); + mocks.proxyWindowSeconds.mockResolvedValue(30); + try { + await captureFindingFrames({ ...PROJECT, dir }, DEFAULT_CHECK_OPTIONS, [ + { time: 1, filename: "a.png" }, + ]); + expect(vi.mocked(serveStaticProjectHtml).mock.calls.at(-1)?.[5]).toEqual( + new Map(names.map((name) => [join(dir, name), 30])), + ); + } finally { + rmSync(dir, { recursive: true, force: true }); + } + }); + it("closes the session when a later screenshot fails", async () => { const dir = mkdtempSync(join(tmpdir(), "finding-frames-failure-")); const page = fakePage(); diff --git a/packages/cli/src/utils/checkBrowser.ts b/packages/cli/src/utils/checkBrowser.ts index b59f970b6a..24b5926e6e 100644 --- a/packages/cli/src/utils/checkBrowser.ts +++ b/packages/cli/src/utils/checkBrowser.ts @@ -45,6 +45,7 @@ import { import { resolveAutoProxy } from "./projectConfig.js"; import { findStageProxyBox } from "./compositionViewport.js"; import { mediaUsedSeconds } from "./mediaUsedSeconds.js"; +import { encodeUrlPath } from "@hyperframes/parsers"; import type { PreviewProxyBox } from "@hyperframes/core"; import { terminalText } from "@hyperframes/core/terminal-text"; import { injectTagsAtHeadStart } from "@hyperframes/core/compiler/html-document"; @@ -223,7 +224,7 @@ async function copyWindows( [...pathnames].map(async (pathname) => { const seconds = used.get(pathname); if (seconds === undefined) return; - const sourcePath = projectLocalFile(projectDir, pathname); + const sourcePath = projectLocalFile(projectDir, encodeUrlPath(pathname)); if (!sourcePath) return; const window = await proxyWindowSeconds(sourcePath, seconds); if (window !== undefined) windows.set(sourcePath, window);