Skip to content

Commit

Permalink
safe text for text block labels
Browse files Browse the repository at this point in the history
  • Loading branch information
walterbender committed Nov 14, 2023
1 parent b70996f commit 4184721
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion js/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -3097,10 +3097,28 @@ class Block {

const labelElem = docById("labelDiv");

var safetext = function(text){
// Best to avoid using these special characters in text strings
// without first converting them to their "safe" form.
var table = {
'<': 'lt',
'>': 'gt',
'"': 'quot',
'\'': 'apos',
'&': 'amp',
'\r': '#10',
'\n': '#13'
};

return text.toString().replace(/[<>"'\r\n&]/g, function(chr){
return '&' + table[chr] + ';';
});
};

if (this.name === "text") {
labelElem.innerHTML =
'<input id="textLabel" style="position: absolute; -webkit-user-select: text;-moz-user-select: text;-ms-user-select: text;" class="text" type="text" value="' +
labelValue +
safetext(labelValue) +
'" />';
labelElem.classList.add("hasKeyboard");
this.label = docById("textLabel");
Expand Down

0 comments on commit 4184721

Please sign in to comment.