@@ -454,11 +454,11 @@ ExecutionVisualizer.prototype.showVizHeaderViewMode = function() {
454454 else {
455455 this . domRoot . find ( '#vizHeader,#vizTitleViewer,#vizDescriptionViewer' ) . show ( ) ;
456456 if ( titleVal ) {
457- this . domRoot . find ( '#vizTitleViewer' ) . html ( htmlspecialchars ( titleVal ) ) ;
457+ this . domRoot . find ( '#vizTitleViewer' ) . html ( htmlsanitize ( titleVal ) ) ; // help prevent HTML/JS injection attacks
458458 }
459459
460460 if ( descVal ) {
461- this . domRoot . find ( '#vizDescriptionViewer' ) . html ( htmlspecialchars ( descVal ) ) ;
461+ this . domRoot . find ( '#vizDescriptionViewer' ) . html ( htmlsanitize ( descVal ) ) ; // help prevent HTML/JS injection attacks
462462 }
463463 }
464464}
@@ -490,7 +490,7 @@ ExecutionVisualizer.prototype.destroyAllAnnotationBubbles = function() {
490490ExecutionVisualizer . prototype . initStepAnnotation = function ( ) {
491491 var curEntry = this . curTrace [ this . curInstr ] ;
492492 if ( curEntry . stepAnnotation ) {
493- this . domRoot . find ( "#stepAnnotationViewer" ) . html ( htmlspecialchars ( curEntry . stepAnnotation ) ) ; // help prevent HTML/JS injection attacks
493+ this . domRoot . find ( "#stepAnnotationViewer" ) . html ( htmlsanitize ( curEntry . stepAnnotation ) ) ; // help prevent HTML/JS injection attacks
494494 this . domRoot . find ( "#stepAnnotationEditor" ) . val ( curEntry . stepAnnotation ) ;
495495 }
496496 else {
@@ -2492,6 +2492,20 @@ function htmlspecialchars(str) {
24922492 return str ;
24932493}
24942494
2495+
2496+ // same as htmlspecialchars except don't worry about expanding spaces or
2497+ // tabs since we want proper word wrapping in divs.
2498+ function htmlsanitize ( str ) {
2499+ if ( typeof ( str ) == "string" ) {
2500+ str = str . replace ( / & / g, "&" ) ; /* must do & first */
2501+
2502+ str = str . replace ( / < / g, "<" ) ;
2503+ str = str . replace ( / > / g, ">" ) ;
2504+ }
2505+ return str ;
2506+ }
2507+
2508+
24952509String . prototype . rtrim = function ( ) {
24962510 return this . replace ( / \s * $ / g, "" ) ;
24972511}
@@ -2744,7 +2758,7 @@ AnnotationBubble.prototype.showViewer = function() {
27442758 // destroy then create a new tip:
27452759 this . destroyQTip ( ) ;
27462760 $ ( this . hashID ) . qtip ( $ . extend ( { } , qtipShared , {
2747- content : htmlspecialchars ( this . text ) , // help prevent HTML/JS injection attacks
2761+ content : htmlsanitize ( this . text ) , // help prevent HTML/JS injection attacks
27482762 id : this . domID ,
27492763 position : {
27502764 my : this . my ,
@@ -2784,7 +2798,7 @@ AnnotationBubble.prototype.minimizeViewer = function() {
27842798
27852799AnnotationBubble . prototype . restoreViewer = function ( ) {
27862800 assert ( this . state == 'minimized' ) ;
2787- $ ( this . hashID ) . qtip ( 'option' , 'content.text' , htmlspecialchars ( this . text ) ) ; // help prevent HTML/JS injection attacks
2801+ $ ( this . hashID ) . qtip ( 'option' , 'content.text' , htmlsanitize ( this . text ) ) ; // help prevent HTML/JS injection attacks
27882802 this . bindViewerClickHandler ( ) ;
27892803 this . state = 'view' ;
27902804}
0 commit comments