From 8986217a73584efdd0688e5e67b28b51940bd02c Mon Sep 17 00:00:00 2001 From: Octopus Date: Tue, 7 Apr 2026 09:44:27 +0800 Subject: [PATCH] fix: prevent SVG data from being misidentified as PNG in MCP export (fixes #644) The fallback condition for PNG detection in the MCP export handler was too broad: it would match any string longer than 100 chars that didn't start with '<', which includes SVG data URLs (data:image/svg+xml;base64,...). This caused a race condition where an autosave SVG export response could arrive while a PNG export was pending, resulting in SVG data being sent to the MCP server as the PNG export result. The server would then try to write it as binary PNG, producing a corrupt file (broken image). Fix: exclude strings starting with 'data:' from the fallback condition, so only raw base64 strings (without a data URL prefix) match as PNG, while SVG data URLs are correctly rejected. --- packages/mcp-server/src/http-server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mcp-server/src/http-server.ts b/packages/mcp-server/src/http-server.ts index d3f868df..eca6a58c 100644 --- a/packages/mcp-server/src/http-server.ts +++ b/packages/mcp-server/src/http-server.ts @@ -684,7 +684,7 @@ function getHtmlPage(sessionId: string): string { // unrelated exports (autosave SVG, sync XML) if (pendingMcpExport) { const d = msg.data; - const isPng = pendingMcpExport === 'png' && (d.startsWith('data:image/png') || (typeof d === 'string' && d.length > 100 && !d.startsWith('<'))); + const isPng = pendingMcpExport === 'png' && (d.startsWith('data:image/png') || (typeof d === 'string' && d.length > 100 && !d.startsWith('<') && !d.startsWith('data:'))); const isSvg = pendingMcpExport === 'svg' && (d.startsWith('data:image/svg') || d.startsWith('