From 328d6a09f40d1290a9fa9b8528578e79bf534635 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 14 Sep 2020 14:58:25 -0400 Subject: [PATCH] Fix broken styling of selectors with pseudo elements Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/382 Additionally, fix minor parsing issues with AdGuard's cosmetic filters. --- src/js/contentscript.js | 10 +++++----- src/js/static-filtering-parser.js | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/js/contentscript.js b/src/js/contentscript.js index 3efd77f75..ed6af7c72 100644 --- a/src/js/contentscript.js +++ b/src/js/contentscript.js @@ -777,11 +777,6 @@ vAPI.injectScriptlet = function(doc, text) { for ( const raw of selectors ) { if ( this.selectors.has(raw) ) { continue; } const o = JSON.parse(raw); - if ( o.pseudo !== undefined ) { - this.domFilterer.addCSSRule(o.selector, vAPI.hideStyle); - mustCommit = true; - continue; - } // CSS selector-based styles. if ( o.action !== undefined && @@ -792,6 +787,11 @@ vAPI.injectScriptlet = function(doc, text) { mustCommit = true; continue; } + if ( o.pseudo !== undefined ) { + this.domFilterer.addCSSRule(o.selector, vAPI.hideStyle); + mustCommit = true; + continue; + } let style, styleToken; if ( o.action === undefined ) { style = vAPI.hideStyle; diff --git a/src/js/static-filtering-parser.js b/src/js/static-filtering-parser.js index 143c06aa1..2a4f823ce 100644 --- a/src/js/static-filtering-parser.js +++ b/src/js/static-filtering-parser.js @@ -1215,6 +1215,7 @@ Parser.prototype.SelectorCompiler = class { if ( hasBits(this.parser.flavorBits, BITFlavorExtStyle) ) { raw = this.translateAdguardCSSInjectionFilter(raw); if ( raw === '' ) { return false; } + this.parser.flavorBits &= ~BITFlavorExtStyle; out.raw = raw; } @@ -1264,7 +1265,7 @@ Parser.prototype.SelectorCompiler = class { } translateAdguardCSSInjectionFilter(suffix) { - const matches = /^([^{]+)\{([^}]+)\}\s*$/.exec(suffix); + const matches = /^(.*)\s*\{([^}]+)\}\s*$/.exec(suffix); if ( matches === null ) { return ''; } const selector = matches[1].trim(); const style = matches[2].trim();