From 4a39081d53cd923d3016c2c00b084c0cab02c28f Mon Sep 17 00:00:00 2001 From: "qunbo.guo" <“1453460532@qq.com”> Date: Mon, 23 Mar 2026 15:45:51 +0800 Subject: [PATCH] fix(chat): preserve image markdown during sanitize Made-with: Cursor --- .../views/chat/components/AgentStreamDisplay.vue | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/frontend/src/views/chat/components/AgentStreamDisplay.vue b/frontend/src/views/chat/components/AgentStreamDisplay.vue index 7e425647..4ce439f4 100644 --- a/frontend/src/views/chat/components/AgentStreamDisplay.vue +++ b/frontend/src/views/chat/components/AgentStreamDisplay.vue @@ -1396,8 +1396,20 @@ const getTokens = (content: any) => { return `\x00TAG${idx}\x00`; }); - let sanitized = sanitizeForDisplay(preserved); + // CRITICAL FIX: Also protect image URLs from sanitizeForDisplay + // Extract image markdown ![alt](url) before sanitization + const imagePlaceholders: string[] = []; + const preservedWithImages = preserved.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, (match) => { + const idx = imagePlaceholders.length; + imagePlaceholders.push(match); + return `\x00IMG${idx}\x00`; + }); + let sanitized = sanitizeForDisplay(preservedWithImages); + + // Restore preserved images + sanitized = sanitized.replace(/\x00IMG(\d+)\x00/g, (_, idx) => imagePlaceholders[Number(idx)]); + // Restore preserved tags sanitized = sanitized.replace(/\x00TAG(\d+)\x00/g, (_, idx) => tagPlaceholders[Number(idx)]);