mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-10-08 18:57:47 +08:00
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.
This commit is contained in:
@@ -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('<svg'));
|
||||
if (isPng || isSvg) {
|
||||
pendingMcpExport = null;
|
||||
|
||||
Reference in New Issue
Block a user