From a08614d37e5a795061c9b8dc60f01750a22132b1 Mon Sep 17 00:00:00 2001 From: David Kutugata Date: Tue, 4 Feb 2020 14:08:14 -0800 Subject: [PATCH 1/4] check if we support mimetypes before loading html to avoid crashing --- src/datascience-ui/interactive-common/cellOutput.tsx | 4 ++-- src/datascience-ui/interactive-common/transforms.tsx | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/datascience-ui/interactive-common/cellOutput.tsx b/src/datascience-ui/interactive-common/cellOutput.tsx index 046d28999d54..4af0d724c6ca 100644 --- a/src/datascience-ui/interactive-common/cellOutput.tsx +++ b/src/datascience-ui/interactive-common/cellOutput.tsx @@ -14,7 +14,7 @@ import { ImageButton } from '../react-common/imageButton'; import { getLocString } from '../react-common/locReactSide'; import { fixLatexEquations } from './latexManipulation'; import { ICellViewModel } from './mainState'; -import { getRichestMimetype, getTransform } from './transforms'; +import { getRichestMimetype, getTransform, isMimeTypeSupported } from './transforms'; // tslint:disable-next-line: no-var-requires no-require-imports const ansiToHtml = require('ansi-to-html'); @@ -380,7 +380,7 @@ export class CellOutput extends React.Component { let mimetype = transformed.mimeType; // If that worked, use the transform - if (mimetype) { + if (mimetype && isMimeTypeSupported(mimetype)) { // Get the matching React.Component for that mimetype const Transform = getTransform(mimetype); diff --git a/src/datascience-ui/interactive-common/transforms.tsx b/src/datascience-ui/interactive-common/transforms.tsx index 2dc7cc51c33b..d4b3a86d511a 100644 --- a/src/datascience-ui/interactive-common/transforms.tsx +++ b/src/datascience-ui/interactive-common/transforms.tsx @@ -151,3 +151,8 @@ export async function forceLoad() { // Used for tests to make sure we don't end up with 'Loading ...' anywhere in a test await Promise.all(mimeTypeToImport.map(m => m.getComponent())); } + +export function isMimeTypeSupported(mimeType: string): Boolean { + const match = mimeTypeToImport.find(m => m.mimeType === mimeType); + return match ? true : false; +} From c2a01d20ffae0d3019dd2d9d9b87828246f121e1 Mon Sep 17 00:00:00 2001 From: David Kutugata Date: Tue, 4 Feb 2020 14:26:37 -0800 Subject: [PATCH 2/4] Silently skip rendering of the scapbook mime types --- src/datascience-ui/interactive-common/cellOutput.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/datascience-ui/interactive-common/cellOutput.tsx b/src/datascience-ui/interactive-common/cellOutput.tsx index 4af0d724c6ca..d3236bc8e394 100644 --- a/src/datascience-ui/interactive-common/cellOutput.tsx +++ b/src/datascience-ui/interactive-common/cellOutput.tsx @@ -405,6 +405,9 @@ export class CellOutput extends React.Component { ); } + } else if (mimetype.startsWith('application/scrapbook.scrap.')) { + // Silently skip rendering of these mime types, render an empty div so the user sees the cell was executed. + buffer.push(
); } else { if (transformed.data) { const keys = Object.keys(transformed.data); From 005a3eaa749419cf6ec70669957cf763537a5c00 Mon Sep 17 00:00:00 2001 From: David Kutugata Date: Tue, 4 Feb 2020 14:31:39 -0800 Subject: [PATCH 3/4] added news file --- news/2 Fixes/9796.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 news/2 Fixes/9796.md diff --git a/news/2 Fixes/9796.md b/news/2 Fixes/9796.md new file mode 100644 index 000000000000..82ff822bd1c7 --- /dev/null +++ b/news/2 Fixes/9796.md @@ -0,0 +1,2 @@ +Silently skip rendering mimetypes related to scrapbook. +Html won't crash if we find a mimetype that we don't support. From e7c533471d522a84931568756f681693ac6d2f72 Mon Sep 17 00:00:00 2001 From: David Kutugata Date: Tue, 4 Feb 2020 16:58:57 -0800 Subject: [PATCH 4/4] updated changelog and deleted news file --- CHANGELOG.md | 3 +++ news/2 Fixes/9796.md | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) delete mode 100644 news/2 Fixes/9796.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 37d7cb8328bf..bcdbb6a4e472 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,9 @@ ### Fixes +1. Removed unnecessary warning when executing cells that use Scrapbook, + Fix an html crash when using not supported mime types + ([#9796](https://github.com/microsoft/vscode-python/issues/9796)) 1. Fixed the focus on the interactive window when pressing ctrl + 1/ ctrl + 2 ([#9693](https://github.com/microsoft/vscode-python/issues/9693)) 1. Fix variable explorer in Interactive and Notebook editors from interfering with execution. diff --git a/news/2 Fixes/9796.md b/news/2 Fixes/9796.md deleted file mode 100644 index 82ff822bd1c7..000000000000 --- a/news/2 Fixes/9796.md +++ /dev/null @@ -1,2 +0,0 @@ -Silently skip rendering mimetypes related to scrapbook. -Html won't crash if we find a mimetype that we don't support.