From c025cc4007d2141c335245b33dfcc102ffc6bbb6 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sat, 8 Oct 2011 19:18:05 +0200 Subject: [PATCH] Match RegExps, do not use eval. Much safer and no need to use try/catch. --- 4chan_x.user.js | 10 +++------- script.coffee | 5 ++--- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index dd282bdd5..b89149c40 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -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]); diff --git a/script.coffee b/script.coffee index 0415eb8f8..250714aa0 100644 --- a/script.coffee +++ b/script.coffee @@ -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