Skip to content

Commit e9d4929

Browse files
committed
fix(canvas): default malformed host base paths
1 parent 00e4d54 commit e9d4929

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

extensions/canvas/src/host/server.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,20 @@ describe("canvas host", () => {
217217
}
218218
});
219219

220+
it("falls back to the default mount when the configured base path is malformed", async () => {
221+
const dir = await createCaseDir();
222+
await fs.writeFile(path.join(dir, "index.html"), "<html><body>fallback</body></html>", "utf8");
223+
const handler = await createTestCanvasHostHandler(dir, { basePath: "/%E0%A4%A" });
224+
225+
try {
226+
const response = await captureHandlerResponse(handler, `${CANVAS_HOST_PATH}/`);
227+
expect(response.status).toBe(200);
228+
expect(response.body).toContain("fallback");
229+
} finally {
230+
await handler.close();
231+
}
232+
});
233+
220234
it("serves canvas content from the mounted base path and reuses handlers without double close", async () => {
221235
const dir = await createCaseDir();
222236
await fs.writeFile(path.join(dir, "index.html"), "<html><body>v1</body></html>", "utf8");

extensions/canvas/src/host/server.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,12 @@ function isDisabledByEnv() {
185185

186186
function normalizeBasePath(rawPath: string | undefined) {
187187
const trimmed = (rawPath ?? CANVAS_HOST_PATH).trim();
188-
const normalized = normalizeUrlPath(trimmed || CANVAS_HOST_PATH);
188+
let normalized: string;
189+
try {
190+
normalized = normalizeUrlPath(trimmed || CANVAS_HOST_PATH);
191+
} catch {
192+
normalized = normalizeUrlPath(CANVAS_HOST_PATH);
193+
}
189194
if (normalized === "/") {
190195
return "/";
191196
}

0 commit comments

Comments
 (0)