This commit is contained in:
gorhill 2016-01-16 20:21:17 -05:00
parent 7dc60b3042
commit 08d7ce96aa
1 changed files with 11 additions and 7 deletions

View File

@ -175,14 +175,14 @@ var isFirstParty = function(domain, hostname) {
hostname.charAt(hostname.length - domain.length - 1) === '.'); hostname.charAt(hostname.length - domain.length - 1) === '.');
}; };
var isBadRegex = function(s) { var normalizeRegexSource = function(s) {
try { try {
void new RegExp(s); var re = new RegExp(s);
return re.source;
} catch (ex) { } catch (ex) {
isBadRegex.message = ex.toString(); normalizeRegexSource.message = ex.toString();
return true;
} }
return false; return '';
}; };
var alwaysTruePseudoRegex = { var alwaysTruePseudoRegex = {
@ -1498,11 +1498,15 @@ FilterParser.prototype.parse = function(raw) {
if ( s.startsWith('/') && s.endsWith('/') && s.length > 2 ) { if ( s.startsWith('/') && s.endsWith('/') && s.length > 2 ) {
this.isRegex = true; this.isRegex = true;
this.f = s.slice(1, -1); 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( console.error(
"uBlock Origin> discarding bad regular expression-based network filter '%s': '%s'", "uBlock Origin> discarding bad regular expression-based network filter '%s': '%s'",
raw, raw,
isBadRegex.message normalizeRegexSource.message
); );
this.unsupported = true; this.unsupported = true;
} }