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

Fix broken token extraction

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1367

Regression from:
- 6ac09a2856

Need to mind wildcards adjacent to extracted token.
This commit is contained in:
Raymond Hill 2020-11-29 07:38:15 -05:00
parent da01ea4671
commit dac8d6becb
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -3152,15 +3152,24 @@ const FilterParser = class {
for (;;) { for (;;) {
const match = this.reToken.exec(pattern); const match = this.reToken.exec(pattern);
if ( match === null ) { break; } if ( match === null ) { break; }
const badness = match[0].length > 1 const token = match[0];
? this.badTokens.get(match[0]) || 0 const badness = token.length > 1 ? this.badTokens.get(token) || 0 : 1;
: 1; if ( badness >= bestBadness ) { continue; }
if ( badness < bestBadness ) { if ( match.index > 0 ) {
const c = pattern.charCodeAt(match.index - 1);
if ( c === 0x2A /* '*' */ ) { continue; }
}
if ( token.length < this.maxTokenLen ) {
const lastIndex = this.reToken.lastIndex;
if ( lastIndex < pattern.length ) {
const c = pattern.charCodeAt(lastIndex);
if ( c === 0x2A /* '*' */ ) { continue; }
}
}
bestMatch = match; bestMatch = match;
if ( badness === 0 ) { break; } if ( badness === 0 ) { break; }
bestBadness = badness; bestBadness = badness;
} }
}
if ( bestMatch !== null ) { if ( bestMatch !== null ) {
this.token = bestMatch[0]; this.token = bestMatch[0];
this.tokenHash = urlTokenizer.tokenHashFromString(this.token); this.tokenHash = urlTokenizer.tokenHashFromString(this.token);