Skip to content

Commit add9ca3

Browse files
authored
Port escape fixes over from python repo (#153)
* Escaping fix broke a number of things (#14145) * Fix linting error
1 parent c350f72 commit add9ca3

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/client/datascience/jupyter/jupyterDebugger.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
'use strict';
44
import type { nbformat } from '@jupyterlab/coreutils';
55
import { inject, injectable, named } from 'inversify';
6+
// tslint:disable-next-line: no-require-imports
7+
import unescape = require('lodash/unescape');
68
import * as uuid from 'uuid/v4';
79
import { DebugConfiguration, Disposable } from 'vscode';
810
import * as vsls from 'vsls/vscode';
@@ -330,8 +332,10 @@ export class JupyterDebugger implements IJupyterDebugger, ICellHashListener {
330332
if (outputs.length > 0) {
331333
const data = outputs[0].data;
332334
if (data && data.hasOwnProperty('text/plain')) {
335+
// Plain text should be escaped by our execution engine. Unescape it so
336+
// we can parse it.
333337
// tslint:disable-next-line:no-any
334-
return (data as any)['text/plain'];
338+
return unescape((data as any)['text/plain']);
335339
}
336340
if (outputs[0].output_type === 'stream') {
337341
const stream = outputs[0] as nbformat.IStream;

src/datascience-ui/interactive-common/cellOutput.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,12 @@ export class CellOutput extends React.Component<ICellOutputProps> {
314314
input = JSON.stringify(output.data);
315315
renderWithScrollbars = true;
316316
isText = true;
317-
} else if (output.output_type === 'execute_result' && input && input.hasOwnProperty('text/plain')) {
317+
} else if (
318+
output.output_type === 'execute_result' &&
319+
input &&
320+
input.hasOwnProperty('text/plain') &&
321+
!input.hasOwnProperty('text/html')
322+
) {
318323
// Plain text should actually be shown as html so that escaped HTML shows up correctly
319324
mimeType = 'text/html';
320325
isText = true;

src/test/datascience/notebook.functional.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ suite('DataScience notebook tests', () => {
180180
const error = cell.outputs[0].evalue;
181181
if (error) {
182182
assert.ok(error, 'Error not found when expected');
183-
assert.equal(error, errorString, 'Unexpected error found');
183+
assert.ok(error.toString().includes(errorString), 'Unexpected error found');
184184
}
185185
}
186186

@@ -716,7 +716,7 @@ suite('DataScience notebook tests', () => {
716716
await server!.waitForIdle(10000);
717717

718718
console.log('Verifying restart');
719-
await verifyError(server, 'a', `name 'a' is not defined`);
719+
await verifyError(server, 'a', `is not defined`);
720720
} catch (exc) {
721721
assert.ok(
722722
exc instanceof JupyterKernelPromiseFailedError,
@@ -990,7 +990,7 @@ a`,
990990
mimeType: 'text/plain',
991991
cellType: 'code',
992992
result: `<a href=f>`,
993-
verifyValue: (d) => assert.equal(d, escape(`<a href=f>`), 'XML not escaped')
993+
verifyValue: (d) => assert.ok(d.includes(escape(`<a href=f>`)), 'XML not escaped')
994994
},
995995
{
996996
markdownRegEx: undefined,

0 commit comments

Comments
 (0)