Match RegExps, do not use eval. Much safer and no need to use try/catch.
This commit is contained in:
parent
90a92bb62e
commit
c025cc4007
@ -530,19 +530,15 @@
|
||||
regexps: {},
|
||||
callbacks: [],
|
||||
init: function() {
|
||||
var filter, key, m, regx, _i, _len;
|
||||
var filter, key, m, _i, _len;
|
||||
for (key in config.filter) {
|
||||
if (!(m = conf[key].match(/(.+)/g))) {
|
||||
if (!(m = conf[key].match(/^(\/.+\/\w{0,})$/gm))) {
|
||||
continue;
|
||||
}
|
||||
this.regexps[key] = [];
|
||||
for (_i = 0, _len = m.length; _i < _len; _i++) {
|
||||
filter = m[_i];
|
||||
try {
|
||||
if ((regx = eval(filter)).constructor === RegExp) {
|
||||
this.regexps[key].push(regx);
|
||||
}
|
||||
} catch (_e) {}
|
||||
this.regexps[key].push(Function("return " + filter)());
|
||||
}
|
||||
if (this.regexps[key].length) {
|
||||
this.callbacks.push(this[key]);
|
||||
|
||||
@ -388,12 +388,11 @@ filter =
|
||||
callbacks: []
|
||||
init: ->
|
||||
for key of config.filter
|
||||
unless m = conf[key].match /(.+)/g
|
||||
unless m = conf[key].match /^(\/.+\/\w{0,})$/gm
|
||||
continue
|
||||
@regexps[key] = []
|
||||
for filter in m
|
||||
try if (regx = eval filter).constructor is RegExp
|
||||
@regexps[key].push regx
|
||||
@regexps[key].push Function("return #{filter}")()
|
||||
#only execute what's filterable
|
||||
@callbacks.push @[key] if @regexps[key].length
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user