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: {},
|
regexps: {},
|
||||||
callbacks: [],
|
callbacks: [],
|
||||||
init: function() {
|
init: function() {
|
||||||
var filter, key, m, regx, _i, _len;
|
var filter, key, m, _i, _len;
|
||||||
for (key in config.filter) {
|
for (key in config.filter) {
|
||||||
if (!(m = conf[key].match(/(.+)/g))) {
|
if (!(m = conf[key].match(/^(\/.+\/\w{0,})$/gm))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this.regexps[key] = [];
|
this.regexps[key] = [];
|
||||||
for (_i = 0, _len = m.length; _i < _len; _i++) {
|
for (_i = 0, _len = m.length; _i < _len; _i++) {
|
||||||
filter = m[_i];
|
filter = m[_i];
|
||||||
try {
|
this.regexps[key].push(Function("return " + filter)());
|
||||||
if ((regx = eval(filter)).constructor === RegExp) {
|
|
||||||
this.regexps[key].push(regx);
|
|
||||||
}
|
|
||||||
} catch (_e) {}
|
|
||||||
}
|
}
|
||||||
if (this.regexps[key].length) {
|
if (this.regexps[key].length) {
|
||||||
this.callbacks.push(this[key]);
|
this.callbacks.push(this[key]);
|
||||||
|
|||||||
@ -388,12 +388,11 @@ filter =
|
|||||||
callbacks: []
|
callbacks: []
|
||||||
init: ->
|
init: ->
|
||||||
for key of config.filter
|
for key of config.filter
|
||||||
unless m = conf[key].match /(.+)/g
|
unless m = conf[key].match /^(\/.+\/\w{0,})$/gm
|
||||||
continue
|
continue
|
||||||
@regexps[key] = []
|
@regexps[key] = []
|
||||||
for filter in m
|
for filter in m
|
||||||
try if (regx = eval filter).constructor is RegExp
|
@regexps[key].push Function("return #{filter}")()
|
||||||
@regexps[key].push regx
|
|
||||||
#only execute what's filterable
|
#only execute what's filterable
|
||||||
@callbacks.push @[key] if @regexps[key].length
|
@callbacks.push @[key] if @regexps[key].length
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user