1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-18 08:52:26 +02:00

Allow empty needle in BidiTrieContainer.lastIndexOf()

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

Related commit:
- https://github.com/gorhill/uBlock/commit/7c0294bd5f54

The changes in the commit above have been reverted, and
the new fix is to add the ability to handle an empty
needle in BidiTrieContainer.lastIndexOf() -- in which
case the method will return the end of the currently
matched pattern.
This commit is contained in:
Raymond Hill 2020-03-19 13:16:41 -04:00
parent c2f0cae2cc
commit a36566b348
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
4 changed files with 8 additions and 14 deletions

View File

@ -2599,20 +2599,6 @@ 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 trailing
// wildcards if any.
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() {

View File

@ -666,6 +666,7 @@ const roundToPageSize = v => (v + PAGE_SIZE-1) & ~(PAGE_SIZE-1);
// Find the right-most instance of substring in main string.
// WASMable.
lastIndexOf(haystackBeg, haystackEnd, needleLeft, needleLen) {
if ( needleLen === 0 ) { return haystackBeg; }
let haystackLeft = haystackEnd - needleLen;
if ( haystackLeft < haystackBeg ) { return -1; }
needleLeft += this.buf32[CHAR0_SLOT];

Binary file not shown.

View File

@ -639,6 +639,13 @@
(local $i i32)
(local $j i32)
(local $c0 i32)
;; if ( needleLen === 0 ) { return haystackBeg; }
get_local $needleLen
i32.eqz
if
get_local $haystackBeg
return
end
block $fail
block $succeed
;; let haystackLeft = haystackEnd - needleLen;