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".
This commit is contained in:
Raymond Hill 2022-01-28 11:18:40 -05:00
parent a5ca565e9c
commit f98b70d1c0
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -416,6 +416,13 @@ const Parser = class {
len === 3 && this.slices[i+2] > 2 || len === 3 && this.slices[i+2] > 2 ||
len > 3 && hasBits(this.slices[i+len-3], BITSlash) 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. // If the pattern is not a regex, there might be options.