diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index f5c42bfd9..0fd0908aa 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -616,6 +616,9 @@ const FilterPatternPlainX = class extends FilterPatternPlain { /******************************************************************************/ +// https://github.com/gorhill/uBlock/commit/7971b223855d#commitcomment-37077525 +// Mind that the left part may be empty. + const FilterPatternLeft = class { constructor(i, n) { this.i = i | 0; @@ -633,8 +636,10 @@ const FilterPatternLeft = class { } logData(details) { + details.pattern.unshift('*'); + if ( this.n === 0 ) { return; } const s = bidiTrie.extractString(this.i, this.n); - details.pattern.unshift(s, '*'); + details.pattern.unshift(s); details.regex.unshift(restrFromPlainPattern(s), '.*'); } @@ -2529,16 +2534,8 @@ const FilterParser = class { 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 + // Since we found a valid token, we can get rid of trailing // wildcards if any. - // https://github.com/gorhill/uBlock/commit/7971b223855d#commitcomment-37077525 - // Mind that changing the pattern may change token start index. - if ( this.firstWildcardPos === 0 ) { - this.f = this.f.slice(1); - this.firstWildcardPos = this.secondWildcardPos; - this.secondWildcardPos = -1; - this.tokenBeg -= 1; - } if ( this.firstWildcardPos !== -1 ) { const lastCharPos = this.f.length - 1; if ( this.firstWildcardPos === lastCharPos ) { diff --git a/src/js/strie.js b/src/js/strie.js index 896a66144..5243ebb83 100644 --- a/src/js/strie.js +++ b/src/js/strie.js @@ -636,6 +636,7 @@ const roundToPageSize = v => (v + PAGE_SIZE-1) & ~(PAGE_SIZE-1); // Find the left-most instance of substring in main string // WASMable. indexOf(haystackLeft, haystackEnd, needleLeft, needleLen) { + if ( needleLen === 0 ) { return haystackLeft; } haystackEnd -= needleLen; if ( haystackEnd < haystackLeft ) { return -1; } needleLeft += this.buf32[CHAR0_SLOT]; diff --git a/src/js/wasm/biditrie.wasm b/src/js/wasm/biditrie.wasm index d9066ae2b..a5d3aef9e 100644 Binary files a/src/js/wasm/biditrie.wasm and b/src/js/wasm/biditrie.wasm differ diff --git a/src/js/wasm/biditrie.wat b/src/js/wasm/biditrie.wat index 9e1df88e0..5f7ec5e46 100644 --- a/src/js/wasm/biditrie.wat +++ b/src/js/wasm/biditrie.wat @@ -544,6 +544,10 @@ (local $c0 i32) block $fail block $succeed + ;; if ( needleLen === 0 ) { return haystackLeft; } + get_local $needleLen + i32.eqz + br_if $succeed ;; haystackEnd -= needleLen; get_local $haystackEnd get_local $needleLen