Merge pull request #236145 from Parasaran-Python/235221

fix 235221: Sanitizing the html content by closing the unclosed tags
pull/236406/head
Matt Bierner 2024-12-17 11:51:22 -08:00 committed by GitHub
commit 5e26b3d7c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 2 deletions

View File

@ -353,6 +353,15 @@ document.addEventListener('click', event => {
}
}, true);
window.addEventListener('load', () => {
const htmlParser = new DOMParser();
const markDownHtml = htmlParser.parseFromString(
decodeURIComponent(getData('data-md-content')),
'text/html'
);
document.body.appendChild(markDownHtml.body);
});
window.addEventListener('scroll', throttle(() => {
updateScrollProgress();

View File

@ -98,13 +98,13 @@ export class MdDocumentRenderer {
<meta id="vscode-markdown-preview-data"
data-settings="${escapeAttribute(JSON.stringify(initialData))}"
data-strings="${escapeAttribute(JSON.stringify(previewStrings))}"
data-state="${escapeAttribute(JSON.stringify(state || {}))}">
data-state="${escapeAttribute(JSON.stringify(state || {}))}"
data-md-content="${escapeAttribute(JSON.stringify(encodeURIComponent(body.html)))}">
<script src="${this._extensionResourcePath(resourceProvider, 'pre.js')}" nonce="${nonce}"></script>
${this._getStyles(resourceProvider, sourceUri, config, imageInfo)}
<base href="${resourceProvider.asWebviewUri(markdownDocument.uri)}">
</head>
<body class="vscode-body ${config.scrollBeyondLastLine ? 'scrollBeyondLastLine' : ''} ${config.wordWrap ? 'wordWrap' : ''} ${config.markEditorSelection ? 'showEditorSelection' : ''}">
${body.html}
${this._getScripts(resourceProvider, nonce)}
</body>
</html>`;