From dac8d6becb2c522f9c0278bb0619c53c3066ece7 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 29 Nov 2020 07:38:15 -0500 Subject: [PATCH] Fix broken token extraction Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/1367 Regression from: - https://github.com/gorhill/uBlock/commit/6ac09a28560ebe7de6c20841b5ffb024fe97442d Need to mind wildcards adjacent to extracted token. --- src/js/static-net-filtering.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index a58e1aa7c..7a58c3775 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -3152,14 +3152,23 @@ const FilterParser = class { for (;;) { const match = this.reToken.exec(pattern); if ( match === null ) { break; } - const badness = match[0].length > 1 - ? this.badTokens.get(match[0]) || 0 - : 1; - if ( badness < bestBadness ) { - bestMatch = match; - if ( badness === 0 ) { break; } - bestBadness = badness; + const token = match[0]; + const badness = token.length > 1 ? this.badTokens.get(token) || 0 : 1; + if ( badness >= bestBadness ) { continue; } + 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; + if ( badness === 0 ) { break; } + bestBadness = badness; } if ( bestMatch !== null ) { this.token = bestMatch[0];