1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Avoid prototype pollution in RED.view.calculateTextDimensions

This commit is contained in:
Nick O'Leary 2021-07-16 08:52:00 +01:00
parent 4b3f5d74a0
commit d4a199f0e1
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -2335,6 +2335,7 @@ RED.view = (function() {
var textDimensionPlaceholder = {}; var textDimensionPlaceholder = {};
var textDimensionCache = {}; var textDimensionCache = {};
function calculateTextDimensions(str,className) { function calculateTextDimensions(str,className) {
var cacheKey = "!"+str;
if (!textDimensionPlaceholder[className]) { if (!textDimensionPlaceholder[className]) {
textDimensionPlaceholder[className] = document.createElement("span"); textDimensionPlaceholder[className] = document.createElement("span");
textDimensionPlaceholder[className].className = className; textDimensionPlaceholder[className].className = className;
@ -2343,15 +2344,15 @@ RED.view = (function() {
document.getElementById("red-ui-editor").appendChild(textDimensionPlaceholder[className]); document.getElementById("red-ui-editor").appendChild(textDimensionPlaceholder[className]);
textDimensionCache[className] = {}; textDimensionCache[className] = {};
} else { } else {
if (textDimensionCache[className][str]) { if (textDimensionCache[className][cacheKey]) {
return textDimensionCache[className][str] return textDimensionCache[className][cacheKey]
} }
} }
textDimensionPlaceholder[className].textContent = (str||""); textDimensionPlaceholder[className].textContent = (str||"");
var w = textDimensionPlaceholder[className].offsetWidth; var w = textDimensionPlaceholder[className].offsetWidth;
var h = textDimensionPlaceholder[className].offsetHeight; var h = textDimensionPlaceholder[className].offsetHeight;
textDimensionCache[className][str] = [w,h]; textDimensionCache[className][cacheKey] = [w,h];
return textDimensionCache[className][str]; return textDimensionCache[className][cacheKey];
} }
function convertLineBreakCharacter(str) { function convertLineBreakCharacter(str) {