Match RegExps, do not use eval. Much safer and no need to use try/catch.

This commit is contained in:
Nicolas Stepien 2011-10-08 19:18:05 +02:00 committed by James Campos
parent 90a92bb62e
commit c025cc4007
2 changed files with 5 additions and 10 deletions

View File

@ -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]);

View File

@ -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