@@ -48,7 +48,7 @@ define([
48
48
OutputArea . config_defaults = {
49
49
stream_chunk_size : 8192 , // chunk size for stream output
50
50
} ;
51
-
51
+
52
52
/**
53
53
* Class prototypes
54
54
**/
@@ -79,17 +79,17 @@ define([
79
79
if ( ! this . prompt_area ) {
80
80
this . prompt_overlay . hide ( ) ;
81
81
}
82
-
82
+
83
83
this . wrapper . addClass ( 'output_wrapper' ) ;
84
84
this . element . addClass ( 'output' ) ;
85
-
85
+
86
86
this . collapse_button . addClass ( "btn btn-default output_collapsed" ) ;
87
87
this . collapse_button . attr ( 'title' , i18n . msg . _ ( 'click to expand output' ) ) ;
88
88
this . collapse_button . text ( '. . .' ) ;
89
-
89
+
90
90
this . prompt_overlay . addClass ( 'out_prompt_overlay prompt' ) ;
91
91
this . prompt_overlay . attr ( 'title' , i18n . msg . _ ( 'click to expand output; double click to hide output' ) ) ;
92
-
92
+
93
93
this . expand ( ) ;
94
94
} ;
95
95
@@ -255,7 +255,7 @@ define([
255
255
}
256
256
this . append_output ( json ) ;
257
257
} ;
258
-
258
+
259
259
// Declare mime type as constants
260
260
var MIME_JAVASCRIPT = 'application/javascript' ;
261
261
var MIME_HTML = 'text/html' ;
@@ -267,8 +267,8 @@ define([
267
267
var MIME_GIF = 'image/gif' ;
268
268
var MIME_PDF = 'application/pdf' ;
269
269
var MIME_TEXT = 'text/plain' ;
270
-
271
-
270
+
271
+
272
272
OutputArea . output_types = [
273
273
MIME_JAVASCRIPT ,
274
274
MIME_HTML ,
@@ -304,10 +304,10 @@ define([
304
304
} ) ;
305
305
return bundle ;
306
306
} ;
307
-
307
+
308
308
OutputArea . prototype . append_output = function ( json ) {
309
309
this . expand ( ) ;
310
-
310
+
311
311
if ( this . clear_queued ) {
312
312
this . clear_output ( false ) ;
313
313
this . _needs_height_reset = true ;
@@ -443,7 +443,7 @@ define([
443
443
. append ( $ ( '<div/>' ) . text ( err . toString ( ) ) . addClass ( 'js-error' ) )
444
444
. append ( $ ( '<div/>' ) . text ( i18n . msg . _ ( 'See your browser Javascript console for more details.' ) ) . addClass ( 'js-error' ) ) ;
445
445
} ;
446
-
446
+
447
447
OutputArea . prototype . _safe_append = function ( toinsert , toreplace ) {
448
448
/**
449
449
* safely append an item to the document
@@ -657,7 +657,7 @@ define([
657
657
element : element ,
658
658
} ) ;
659
659
} ;
660
-
660
+
661
661
OutputArea . prototype . append_display_data = function ( json , handle_inserted ) {
662
662
var toinsert = this . create_output_area ( ) ;
663
663
this . _record_display_id ( json , toinsert ) ;
@@ -682,36 +682,43 @@ define([
682
682
OutputArea . prototype . append_mime_type = function ( json , element , handle_inserted ) {
683
683
for ( var i = 0 ; i < OutputArea . display_order . length ; i ++ ) {
684
684
var type = OutputArea . display_order [ i ] ;
685
- var append = OutputArea . append_map [ type ] ;
686
- if ( ( json . data [ type ] !== undefined ) && append ) {
687
- var md = json . metadata || { } ;
688
- var value = json . data [ type ] ;
689
- var toinsert ;
690
- if ( ! this . trusted && ! OutputArea . safe_outputs [ type ] ) {
691
- // not trusted, sanitize HTML
692
- if ( type === MIME_HTML || type === 'text/svg' ) {
693
- var parsed = $ ( security . sanitize_html_and_parse ( value ) ) ;
694
- toinsert = append . apply ( this , [ parsed , md , element , handle_inserted ] ) ;
685
+
686
+ try {
687
+ var append = OutputArea . append_map [ type ] ;
688
+ if ( ( json . data [ type ] !== undefined ) && append ) {
689
+ var md = json . metadata || { } ;
690
+ var value = json . data [ type ] ;
691
+ var toinsert ;
692
+ if ( ! this . trusted && ! OutputArea . safe_outputs [ type ] ) {
693
+ // not trusted, sanitize HTML
694
+ if ( type === MIME_HTML || type === 'text/svg' ) {
695
+ var parsed = $ ( security . sanitize_html_and_parse ( value ) ) ;
696
+ toinsert = append . apply ( this , [ parsed , md , element , handle_inserted ] ) ;
697
+ } else {
698
+ // don't display if we don't know how to sanitize it
699
+ console . log ( "Ignoring untrusted " + type + " output." ) ;
700
+ continue ;
701
+ }
695
702
} else {
696
- // don't display if we don't know how to sanitize it
697
- console . log ( "Ignoring untrusted " + type + " output." ) ;
698
- continue ;
703
+ toinsert = append . apply ( this , [ value , md , element , handle_inserted ] ) ;
699
704
}
700
- } else {
701
- toinsert = append . apply ( this , [ value , md , element , handle_inserted ] ) ;
702
- }
703
705
704
- // Since only the png and jpeg mime types call the inserted
705
- // callback, if the mime type is something other we must call the
706
- // inserted callback only when the element is actually inserted
707
- // into the DOM. Use a timeout of 0 to do this.
708
- if ( [ MIME_PNG , MIME_JPEG , MIME_GIF ] . indexOf ( type ) < 0 && handle_inserted !== undefined ) {
709
- setTimeout ( handle_inserted , 0 ) ;
706
+ // Since only the png and jpeg mime types call the inserted
707
+ // callback, if the mime type is something other we must call the
708
+ // inserted callback only when the element is actually inserted
709
+ // into the DOM. Use a timeout of 0 to do this.
710
+ if ( [ MIME_PNG , MIME_JPEG , MIME_GIF ] . indexOf ( type ) < 0 && handle_inserted !== undefined ) {
711
+ setTimeout ( handle_inserted , 0 ) ;
712
+ }
713
+ this . events . trigger ( 'output_appended.OutputArea' , [ type , value , md , toinsert ] ) ;
714
+ return toinsert ;
710
715
}
711
- this . events . trigger ( 'output_appended.OutputArea' , [ type , value , md , toinsert ] ) ;
712
- return toinsert ;
716
+ } catch ( e ) {
717
+ console . error ( 'Failed to render mimetype "' + type + '" with: ' , e ) ;
718
+ continue ;
713
719
}
714
720
}
721
+
715
722
return null ;
716
723
} ;
717
724
@@ -783,7 +790,7 @@ define([
783
790
var type = MIME_SVG ;
784
791
var toinsert = this . create_output_subarea ( md , "output_svg" , type ) ;
785
792
786
- // Get the svg element from within the HTML.
793
+ // Get the svg element from within the HTML.
787
794
// One svg is supposed, but could embed other nested svgs
788
795
var svg = $ ( $ ( '<div \>' ) . html ( svg_html ) . find ( 'svg' ) [ 0 ] ) ;
789
796
var svg_area = $ ( '<div />' ) ;
@@ -819,7 +826,7 @@ define([
819
826
}
820
827
} ) ;
821
828
}
822
-
829
+
823
830
var set_width_height = function ( img , md , mime ) {
824
831
/**
825
832
* set width and height of an img element from metadata
@@ -832,7 +839,7 @@ define([
832
839
img . addClass ( 'unconfined' ) ;
833
840
}
834
841
} ;
835
-
842
+
836
843
OutputArea . prototype . _append_img = function ( src_type , md , element , handle_inserted , MIME , type_string ) {
837
844
var type = MIME ;
838
845
var toinsert = this . create_output_subarea ( md , 'output_' + type_string , type ) ;
@@ -849,15 +856,15 @@ define([
849
856
element . append ( toinsert ) ;
850
857
return toinsert ;
851
858
} ;
852
-
859
+
853
860
var append_png = function ( png , md , element , handle_inserted ) {
854
861
return this . _append_img ( png , md , element , handle_inserted , MIME_PNG , 'png' ) ;
855
862
} ;
856
863
857
864
var append_jpeg = function ( jpeg , md , element , handle_inserted ) {
858
865
return this . _append_img ( jpeg , md , element , handle_inserted , MIME_JPEG , 'jpeg' ) ;
859
866
} ;
860
-
867
+
861
868
var append_gif = function ( gif , md , element , handle_inserted ) {
862
869
return this . _append_img ( gif , md , element , handle_inserted , MIME_GIF , 'gif' ) ;
863
870
} ;
@@ -884,18 +891,18 @@ define([
884
891
element . append ( toinsert ) ;
885
892
return toinsert ;
886
893
} ;
887
-
894
+
888
895
OutputArea . prototype . append_raw_input = function ( msg ) {
889
896
var that = this ;
890
897
this . expand ( ) ;
891
898
var content = msg . content ;
892
899
var area = this . create_output_area ( ) ;
893
-
900
+
894
901
// disable any other raw_inputs, if they are left around
895
902
$ ( "div.output_subarea.raw_input_container" ) . remove ( ) ;
896
-
903
+
897
904
var input_type = content . password ? 'password' : 'text' ;
898
-
905
+
899
906
area . append (
900
907
$ ( "<div/>" )
901
908
. addClass ( "box-flex1 output_subarea raw_input_container" )
@@ -920,7 +927,7 @@ define([
920
927
)
921
928
. attr ( "dir" , "auto" )
922
929
) ;
923
-
930
+
924
931
this . element . append ( area ) ;
925
932
var raw_input = area . find ( 'input.raw_input' ) ;
926
933
// Register events that enable/disable the keyboard manager while raw
@@ -986,7 +993,7 @@ define([
986
993
this . element . height ( height ) ;
987
994
this . clear_queued = false ;
988
995
}
989
-
996
+
990
997
// Clear all
991
998
// Remove load event handlers from img tags because we don't want
992
999
// them to fire if the image is never added to the page.
@@ -997,7 +1004,7 @@ define([
997
1004
// Notify others of changes.
998
1005
this . element . trigger ( 'changed' , { output_area : this } ) ;
999
1006
this . element . trigger ( 'cleared' , { output_area : this } ) ;
1000
-
1007
+
1001
1008
this . outputs = [ ] ;
1002
1009
this . _display_id_targets = { } ;
1003
1010
this . trusted = true ;
@@ -1104,11 +1111,11 @@ define([
1104
1111
OutputArea . append_map [ MIME_LATEX ] = append_latex ;
1105
1112
OutputArea . append_map [ MIME_JAVASCRIPT ] = append_javascript ;
1106
1113
OutputArea . append_map [ MIME_PDF ] = append_pdf ;
1107
-
1114
+
1108
1115
OutputArea . prototype . mime_types = function ( ) {
1109
1116
return OutputArea . display_order ;
1110
1117
} ;
1111
-
1118
+
1112
1119
OutputArea . prototype . register_mime_type = function ( mimetype , append , options ) {
1113
1120
if ( mimetype && typeof ( append ) === 'function' ) {
1114
1121
OutputArea . output_types . push ( mimetype ) ;
0 commit comments