diff --git a/src/vs/workbench/parts/extensions/browser/extensionEditor.ts b/src/vs/workbench/parts/extensions/browser/extensionEditor.ts index abb31842241..e6ed7ac991a 100644 --- a/src/vs/workbench/parts/extensions/browser/extensionEditor.ts +++ b/src/vs/workbench/parts/extensions/browser/extensionEditor.ts @@ -62,6 +62,27 @@ function renderBody(body: string): string { `; } +function removeEmbeddedSVGs(documentContent: string): string { + const newDocument = new DOMParser().parseFromString(documentContent, 'text/html'); + + // remove all inline svgs + const allSVGs = newDocument.documentElement.querySelectorAll('svg'); + for (let i = 0; i < allSVGs.length; i++) { + allSVGs[i].parentNode.removeChild(allSVGs[i]); + } + + // remove all svgs encoded as data uris + const allImages = newDocument.documentElement.querySelectorAll('img'); + for (let i = 0; i < allImages.length; i++) { + let source = allImages[i].getAttribute('src'); + if (source && source.indexOf('data:image/svg') === 0) { + allImages[i].parentNode.removeChild(allImages[i]); + } + } + const sanitizedContent = newDocument.documentElement.outerHTML; + return sanitizedContent; +} + class NavBar { private _onChange = new Emitter(); @@ -322,6 +343,7 @@ export class ExtensionEditor extends BaseEditor { return this.loadContents(() => content .then(marked.parse) .then(renderBody) + .then(removeEmbeddedSVGs) .then(body => { const webview = new WebView(this.content, this.partService.getContainer(Parts.EDITOR_PART)); const removeLayoutParticipant = arrays.insert(this.layoutParticipants, webview);