From 8704e4e62050095c2927be0dce172cd766bc7672 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 9 Jan 2020 10:09:51 -0500 Subject: [PATCH] Improve token extraction from regex-based filters Tokens which are as long or longer than the max token length possible do not need to have the prefix part evaluated against special regex characters. This will help increase the likelihood of extracting a valid token from regex-based filters. Actual case found in EasyPrivacy: /^https?:\/\/eulerian..*\/[a-z0-9]{2,12}\.js/$script Before this commit, uBO was not able to extract a valid token, while now uBO is able to extract `eulerian` as a valid token (consequently the regex-based filter will now be evaluated only when the token `euleria` is found in a URL). --- src/js/static-net-filtering.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index f8270dbef..36174a383 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -2591,8 +2591,12 @@ const FilterParser = class { const prefix = s.slice(0, matches.index); if ( this.reRegexTokenAbort.test(prefix) ) { return; } if ( - this.reRegexBadPrefix.test(prefix) || - this.reRegexBadSuffix.test(s.slice(this.reRegexToken.lastIndex)) + this.reRegexBadPrefix.test(prefix) || ( + matches[0].length < this.maxTokenLen && + this.reRegexBadSuffix.test( + s.slice(this.reRegexToken.lastIndex) + ) + ) ) { continue; }