Add support for EasyList { remove: true } cosmetic filter syntax

Related issue:
https://github.com/uBlockOrigin/uBlock-issues/issues/3451
This commit is contained in:
Raymond Hill 2024-11-14 10:24:50 -05:00
parent 2e745f9bfb
commit ff5fc61753
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -3345,10 +3345,13 @@ class ExtSelectorCompiler {
// We have an Adguard/ABP cosmetic filter if and only if the
// character is `$`, `%` or `?`, otherwise it's not a cosmetic
// filter.
// Adguard's style injection: translate to uBO's format.
if ( compileOptions.adgStyleSyntax === true ) {
raw = this.translateAdguardCSSInjectionFilter(raw);
if ( raw === '' ) { return false; }
// Adguard/EasyList style injection: translate to uBO's format.
if ( this.isStyleInjectionFilter(raw) ) {
const translated = this.translateStyleInjectionFilter(raw);
if ( translated === undefined ) { return false; }
raw = translated;
} else if ( compileOptions.adgStyleSyntax === true ) {
return false;
}
// Normalize AdGuard's attribute-based procedural operators.
@ -3884,9 +3887,14 @@ class ExtSelectorCompiler {
return true;
}
translateAdguardCSSInjectionFilter(suffix) {
const matches = /^(.*)\s*\{([^}]+)\}\s*$/.exec(suffix);
if ( matches === null ) { return ''; }
isStyleInjectionFilter(selector) {
const len = selector.length;
return len !== 0 && selector.charCodeAt(len-1) === 0x7D /* } */;
}
translateStyleInjectionFilter(raw) {
const matches = /^(.+)\s*\{([^}]+)\}$/.exec(raw);
if ( matches === null ) { return; }
const selector = matches[1].trim();
const style = matches[2].trim();
// Special style directive `remove: true` is converted into a