replace eval with JSON.parse and egw.applyFunc

This commit is contained in:
Ralf Becker 2021-03-15 08:56:58 +02:00
parent c18e1107dd
commit 3fdf4057d6
2 changed files with 25 additions and 2 deletions

View File

@ -410,7 +410,18 @@ var AdminApp = /** @class */ (function (_super) {
this.load(link);
}
else if (link.substr(0, 11) == 'javascript:') {
eval(link.substr(11));
var href_regexp = /^javascript:([^\(]+)\((.*)?\);?$/;
var matches = link.match(href_regexp);
var args = [];
if (matches.length > 1 && matches[2] !== undefined) {
try {
args = JSON.parse('[' + matches[2] + ']');
}
catch (e) { // deal with '-encloded strings (JSON allows only ")
args = JSON.parse('[' + matches[2].replace(/'/g, '"') + ']');
}
}
egw.applyFunc(matches[1], args);
}
};
/**

View File

@ -454,7 +454,19 @@ class AdminApp extends EgwApp
}
else if (link.substr(0,11) == 'javascript:')
{
eval(link.substr(11));
const href_regexp = /^javascript:([^\(]+)\((.*)?\);?$/;
const matches = link.match(href_regexp);
let args = [];
if (matches.length > 1 && matches[2] !== undefined)
{
try {
args = JSON.parse('['+matches[2]+']');
}
catch(e) { // deal with '-encloded strings (JSON allows only ")
args = JSON.parse('['+matches[2].replace(/'/g, '"')+']');
}
}
egw.applyFunc(matches[1], args);
}
}