From ca721227517f2ad0f737f0fde18df588beb96c67 Mon Sep 17 00:00:00 2001 From: Parasaran Date: Tue, 17 Dec 2024 23:32:42 +0530 Subject: [PATCH] fix 235221: Encode and decode markdown content to escape illegal chars --- extensions/markdown-language-features/preview-src/index.ts | 5 ++++- .../src/preview/documentRenderer.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/extensions/markdown-language-features/preview-src/index.ts b/extensions/markdown-language-features/preview-src/index.ts index d7fa1f18d76..336245a1fdf 100644 --- a/extensions/markdown-language-features/preview-src/index.ts +++ b/extensions/markdown-language-features/preview-src/index.ts @@ -355,7 +355,10 @@ document.addEventListener('click', event => { window.addEventListener('load', () => { const htmlParser = new DOMParser(); - const markDownHtml = htmlParser.parseFromString(getData('data-md-content'), 'text/html'); + const markDownHtml = htmlParser.parseFromString( + decodeURIComponent(getData('data-md-content')), + 'text/html' + ); document.body.appendChild(markDownHtml.body); }); diff --git a/extensions/markdown-language-features/src/preview/documentRenderer.ts b/extensions/markdown-language-features/src/preview/documentRenderer.ts index f2447532e00..13e709c765f 100644 --- a/extensions/markdown-language-features/src/preview/documentRenderer.ts +++ b/extensions/markdown-language-features/src/preview/documentRenderer.ts @@ -99,7 +99,7 @@ export class MdDocumentRenderer { data-settings="${escapeAttribute(JSON.stringify(initialData))}" data-strings="${escapeAttribute(JSON.stringify(previewStrings))}" data-state="${escapeAttribute(JSON.stringify(state || {}))}" - data-md-content="${escapeAttribute(JSON.stringify(body.html))}"> + data-md-content="${escapeAttribute(JSON.stringify(encodeURIComponent(body.html)))}"> ${this._getStyles(resourceProvider, sourceUri, config, imageInfo)}