@@ -40,6 +40,10 @@ import { KernelConnectionMetadata } from './kernels/types';
40
40
41
41
// tslint:disable-next-line: no-require-imports
42
42
import cloneDeep = require( 'lodash/cloneDeep' ) ;
43
+ // tslint:disable-next-line: no-require-imports
44
+ import escape = require( 'lodash/escape' ) ;
45
+ // tslint:disable-next-line: no-require-imports
46
+ import unescape = require( 'lodash/unescape' ) ;
43
47
import { concatMultilineString , formatStreamText } from '../../../datascience-ui/common' ;
44
48
import { RefBool } from '../../common/refBool' ;
45
49
import { PythonEnvironment } from '../../pythonEnvironments/info' ;
@@ -783,12 +787,12 @@ export class JupyterNotebookBase implements INotebook {
783
787
outputs . forEach ( ( o ) => {
784
788
if ( o . output_type === 'stream' ) {
785
789
const stream = o as nbformat . IStream ;
786
- result = result . concat ( formatStreamText ( concatMultilineString ( stream . text , true ) ) ) ;
790
+ result = result . concat ( formatStreamText ( unescape ( concatMultilineString ( stream . text , true ) ) ) ) ;
787
791
} else {
788
792
const data = o . data ;
789
793
if ( data && data . hasOwnProperty ( 'text/plain' ) ) {
790
794
// tslint:disable-next-line:no-any
791
- result = result . concat ( ( data as any ) [ 'text/plain' ] ) ;
795
+ result = result . concat ( unescape ( ( data as any ) [ 'text/plain' ] ) ) ;
792
796
}
793
797
}
794
798
} ) ;
@@ -1233,7 +1237,7 @@ export class JupyterNotebookBase implements INotebook {
1233
1237
) {
1234
1238
// Check our length on text output
1235
1239
if ( msg . content . data && msg . content . data . hasOwnProperty ( 'text/plain' ) ) {
1236
- msg . content . data [ 'text/plain' ] = trimFunc ( msg . content . data [ 'text/plain' ] as string ) ;
1240
+ msg . content . data [ 'text/plain' ] = escape ( trimFunc ( msg . content . data [ 'text/plain' ] as string ) ) ;
1237
1241
}
1238
1242
1239
1243
this . addToCellData (
@@ -1262,7 +1266,7 @@ export class JupyterNotebookBase implements INotebook {
1262
1266
if ( o . data && o . data . hasOwnProperty ( 'text/plain' ) ) {
1263
1267
// tslint:disable-next-line: no-any
1264
1268
const str = ( o . data as any ) [ 'text/plain' ] . toString ( ) ;
1265
- const data = trimFunc ( str ) as string ;
1269
+ const data = escape ( trimFunc ( str ) ) as string ;
1266
1270
this . addToCellData (
1267
1271
cell ,
1268
1272
{
@@ -1310,13 +1314,13 @@ export class JupyterNotebookBase implements INotebook {
1310
1314
: undefined ;
1311
1315
if ( existing ) {
1312
1316
// tslint:disable-next-line:restrict-plus-operands
1313
- existing . text = existing . text + msg . content . text ;
1317
+ existing . text = existing . text + escape ( msg . content . text ) ;
1314
1318
const originalText = formatStreamText ( concatMultilineString ( existing . text ) ) ;
1315
1319
originalTextLength = originalText . length ;
1316
1320
existing . text = trimFunc ( originalText ) ;
1317
1321
trimmedTextLength = existing . text . length ;
1318
1322
} else {
1319
- const originalText = formatStreamText ( concatMultilineString ( msg . content . text ) ) ;
1323
+ const originalText = formatStreamText ( concatMultilineString ( escape ( msg . content . text ) ) ) ;
1320
1324
originalTextLength = originalText . length ;
1321
1325
// Create a new stream entry
1322
1326
const output : nbformat . IStream = {
@@ -1346,6 +1350,11 @@ export class JupyterNotebookBase implements INotebook {
1346
1350
}
1347
1351
1348
1352
private handleDisplayData ( msg : KernelMessage . IDisplayDataMsg , clearState : RefBool , cell : ICell ) {
1353
+ // Escape text output
1354
+ if ( msg . content . data && msg . content . data . hasOwnProperty ( 'text/plain' ) ) {
1355
+ msg . content . data [ 'text/plain' ] = escape ( msg . content . data [ 'text/plain' ] as string ) ;
1356
+ }
1357
+
1349
1358
const output : nbformat . IDisplayData = {
1350
1359
output_type : 'display_data' ,
1351
1360
data : msg . content . data ,
@@ -1393,9 +1402,9 @@ export class JupyterNotebookBase implements INotebook {
1393
1402
private handleError ( msg : KernelMessage . IErrorMsg , clearState : RefBool , cell : ICell ) {
1394
1403
const output : nbformat . IError = {
1395
1404
output_type : 'error' ,
1396
- ename : msg . content . ename ,
1397
- evalue : msg . content . evalue ,
1398
- traceback : msg . content . traceback
1405
+ ename : escape ( msg . content . ename ) ,
1406
+ evalue : escape ( msg . content . evalue ) ,
1407
+ traceback : msg . content . traceback . map ( escape )
1399
1408
} ;
1400
1409
this . addToCellData ( cell , output , clearState ) ;
1401
1410
cell . state = CellState . error ;
0 commit comments