From 08d7ce96aa4b9dd419a2fa6157ee4b7a5021ceac Mon Sep 17 00:00:00 2001 From: gorhill Date: Sat, 16 Jan 2016 20:21:17 -0500 Subject: [PATCH] this fixes #1246 --- src/js/static-net-filtering.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index e7ec8c8b0..24b130278 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -175,14 +175,14 @@ var isFirstParty = function(domain, hostname) { hostname.charAt(hostname.length - domain.length - 1) === '.'); }; -var isBadRegex = function(s) { +var normalizeRegexSource = function(s) { try { - void new RegExp(s); + var re = new RegExp(s); + return re.source; } catch (ex) { - isBadRegex.message = ex.toString(); - return true; + normalizeRegexSource.message = ex.toString(); } - return false; + return ''; }; var alwaysTruePseudoRegex = { @@ -1498,11 +1498,15 @@ FilterParser.prototype.parse = function(raw) { if ( s.startsWith('/') && s.endsWith('/') && s.length > 2 ) { this.isRegex = true; this.f = s.slice(1, -1); - if ( isBadRegex(this.f) ) { + // https://github.com/gorhill/uBlock/issues/1246 + // If the filter is valid, use the corrected version of the source + // string -- this ensure reverse-lookup will work fine. + this.f = normalizeRegexSource(this.f); + if ( this.f === '' ) { console.error( "uBlock Origin> discarding bad regular expression-based network filter '%s': '%s'", raw, - isBadRegex.message + normalizeRegexSource.message ); this.unsupported = true; }