From 7c0294bd5f541951c45f3841cfad7dddfd52be4d Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 31 Oct 2019 13:46:06 -0400 Subject: [PATCH] Fix spurious leading/trailing wildcards with valid token Related feedback: - https://www.reddit.com/r/uBlockOrigin/comments/dpcvfx/ Regression from: - https://github.com/gorhill/uBlock/commit/7971b223855d3afae2ca57565f27da0631a1b045 Leading/trailing wildcards are useless when a valid token can be found, and in such case they need to be removed so as to ensure the proper filter class is used. --- src/js/static-net-filtering.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index a7d7ed69f..3138b4cba 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -2527,6 +2527,25 @@ const FilterParser = class { this.token = matches[0]; this.tokenHash = urlTokenizer.tokenHashFromString(this.token); this.tokenBeg = matches.index; + + // https://www.reddit.com/r/uBlockOrigin/comments/dpcvfx/ + // Since we found a valid token, we can get rid of leading/trailing + // wildcards if any. + if ( this.firstWildcardPos === 0 ) { + this.f = this.f.slice(1); + this.firstWildcardPos = this.secondWildcardPos; + this.secondWildcardPos = -1; + } + if ( this.firstWildcardPos !== -1 ) { + const lastCharPos = this.f.length - 1; + if ( this.firstWildcardPos === lastCharPos ) { + this.f = this.f.slice(0, -1); + this.firstWildcardPos = -1; + } else if ( this.secondWildcardPos === lastCharPos ) { + this.f = this.f.slice(0, -1); + this.secondWildcardPos = -1; + } + } } findGoodToken() {