Skip to content

Commit d4f4cbe

Browse files
author
Philip Guo
committed
ah bug relating to &nbsp NON-BREAKING space no wrapping around divs
1 parent 5ea2410 commit d4f4cbe

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

‎v3/css/pytutor.css‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ div.ExecutionVisualizer .vizTitleText {
675675

676676
div.ExecutionVisualizer div#vizHeader {
677677
margin-bottom: 10px;
678-
width: 800px;
679-
max-width: 800px;
678+
width: 700px;
679+
max-width: 700px;
680680
}
681681

‎v3/js/pytutor.js‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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() {
490490
ExecutionVisualizer.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, "&lt;");
2503+
str = str.replace(/>/g, "&gt;");
2504+
}
2505+
return str;
2506+
}
2507+
2508+
24952509
String.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

27852799
AnnotationBubble.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

Comments
 (0)