1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-07 03:12:33 +01:00

Fix spurious leading/trailing wildcards with valid token

Related feedback:
- https://www.reddit.com/r/uBlockOrigin/comments/dpcvfx/

Regression from:
- 7971b22385

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.
This commit is contained in:
Raymond Hill 2019-10-31 13:46:06 -04:00
parent eb23c3581a
commit 7c0294bd5f
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -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() {