Skip to content

Commit 5e26b3d

Browse files
authored
Merge pull request microsoft#236145 from Parasaran-Python/235221
fix 235221: Sanitizing the html content by closing the unclosed tags
2 parents b3b7f0e + ca72122 commit 5e26b3d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

extensions/markdown-language-features/preview-src/index.ts

+9
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,15 @@ document.addEventListener('click', event => {
353353
}
354354
}, true);
355355

356+
window.addEventListener('load', () => {
357+
const htmlParser = new DOMParser();
358+
const markDownHtml = htmlParser.parseFromString(
359+
decodeURIComponent(getData('data-md-content')),
360+
'text/html'
361+
);
362+
document.body.appendChild(markDownHtml.body);
363+
});
364+
356365
window.addEventListener('scroll', throttle(() => {
357366
updateScrollProgress();
358367

extensions/markdown-language-features/src/preview/documentRenderer.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ export class MdDocumentRenderer {
9898
<meta id="vscode-markdown-preview-data"
9999
data-settings="${escapeAttribute(JSON.stringify(initialData))}"
100100
data-strings="${escapeAttribute(JSON.stringify(previewStrings))}"
101-
data-state="${escapeAttribute(JSON.stringify(state || {}))}">
101+
data-state="${escapeAttribute(JSON.stringify(state || {}))}"
102+
data-md-content="${escapeAttribute(JSON.stringify(encodeURIComponent(body.html)))}">
102103
<script src="${this._extensionResourcePath(resourceProvider, 'pre.js')}" nonce="${nonce}"></script>
103104
${this._getStyles(resourceProvider, sourceUri, config, imageInfo)}
104105
<base href="${resourceProvider.asWebviewUri(markdownDocument.uri)}">
105106
</head>
106107
<body class="vscode-body ${config.scrollBeyondLastLine ? 'scrollBeyondLastLine' : ''} ${config.wordWrap ? 'wordWrap' : ''} ${config.markEditorSelection ? 'showEditorSelection' : ''}">
107-
${body.html}
108108
${this._getScripts(resourceProvider, nonce)}
109109
</body>
110110
</html>`;

0 commit comments

Comments
 (0)