From bc19a938152a7839079cb189a8d5ce660ed71d0b Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Wed, 1 Feb 2023 11:24:07 -0500 Subject: [PATCH] Ignore compilation hints when applying exception cosmetic filters Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/2475 --- src/js/cosmetic-filtering.js | 28 ++++++++++++++++------------ src/js/static-filtering-parser.js | 4 ++-- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/js/cosmetic-filtering.js b/src/js/cosmetic-filtering.js index ee8487714..ab89bd3d9 100644 --- a/src/js/cosmetic-filtering.js +++ b/src/js/cosmetic-filtering.js @@ -682,8 +682,7 @@ FilterContainer.prototype.disableSurveyor = function(details) { /******************************************************************************/ -FilterContainer.prototype.cssRuleFromProcedural = function(json) { - const pfilter = JSON.parse(json); +FilterContainer.prototype.cssRuleFromProcedural = function(pfilter) { if ( pfilter.cssable !== true ) { return; } const { tasks, action } = pfilter; let mq; @@ -839,15 +838,13 @@ FilterContainer.prototype.retrieveSpecificSelectors = function( 2 ); + // Apply exceptions to specific filterset if ( exceptionSet.size !== 0 ) { out.exceptionFilters = Array.from(exceptionSet); - for ( const exception of exceptionSet ) { - if ( - specificSet.delete(exception) || - proceduralSet.delete(exception) - ) { - out.exceptedFilters.push(exception); - } + for ( const selector of specificSet ) { + if ( exceptionSet.has(selector) === false ) { continue; } + specificSet.delete(selector); + out.exceptedFilters.push(selector); } } @@ -857,11 +854,18 @@ FilterContainer.prototype.retrieveSpecificSelectors = function( ); } - // Some procedural filters are really declarative cosmetic filters, so - // we extract and inject them immediately. + // Apply exceptions to procedural filterset. + // Also, some procedural filters are really declarative cosmetic + // filters, so we extract and inject them immediately. if ( proceduralSet.size !== 0 ) { for ( const json of proceduralSet ) { - const cssRule = this.cssRuleFromProcedural(json); + const pfilter = JSON.parse(json); + if ( exceptionSet.has(pfilter.raw) ) { + proceduralSet.delete(json); + out.exceptedFilters.push(pfilter.raw); + continue; + } + const cssRule = this.cssRuleFromProcedural(pfilter); if ( cssRule === undefined ) { continue; } injectedCSS.push(cssRule); proceduralSet.delete(json); diff --git a/src/js/static-filtering-parser.js b/src/js/static-filtering-parser.js index f069bb4d2..b750c663d 100644 --- a/src/js/static-filtering-parser.js +++ b/src/js/static-filtering-parser.js @@ -2982,7 +2982,7 @@ class ExtSelectorCompiler { if ( hasArgs ) { const arg = this.astSerialize(part.args); if ( typeof arg !== 'string' ) { return; } - out.push(`(${arg})`); + out.push(`(${arg.trim()})`); } break; } @@ -3101,7 +3101,7 @@ class ExtSelectorCompiler { } if ( tasks.length === 0 && out.action === undefined ) { if ( prelude.length === 0 ) { return; } - return prelude.join(''); + return prelude.join('').trim(); } if ( prelude.length !== 0 ) { tasks.push(this.createSpathTask(prelude.join('')));