From f98b70d1c0bd01578c0dcdf662f5c5cddd5a7d81 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 28 Jan 2022 11:18:40 -0500 Subject: [PATCH] Improve dealing with ambiguity in regex-based-looking network filters Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/1932 Reported in point 3 under "Actual behavior". --- src/js/static-filtering-parser.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/js/static-filtering-parser.js b/src/js/static-filtering-parser.js index f6bb5b976..4700db4ce 100644 --- a/src/js/static-filtering-parser.js +++ b/src/js/static-filtering-parser.js @@ -416,6 +416,13 @@ const Parser = class { len === 3 && this.slices[i+2] > 2 || len > 3 && hasBits(this.slices[i+len-3], BITSlash) ); + // https://github.com/uBlockOrigin/uBlock-issues/issues/1932 + // Resolve ambiguity with options ending with `/` by verifying + // that when a `$` is present, what follows make sense regex-wise. + if ( patternIsRegex && hasBits(this.allBits, BITDollar) ) { + patternIsRegex = + this.strFromSpan(this.patternSpan).search(/[^\\]\$[^/|)]/) === -1; + } } // If the pattern is not a regex, there might be options.