Skip to content

Commit

Permalink
Fix broken styling of selectors with pseudo elements
Browse files Browse the repository at this point in the history
Related issue:
- uBlockOrigin/uBlock-issues#382

Additionally, fix minor parsing issues with AdGuard's
cosmetic filters.
  • Loading branch information
gorhill committed Sep 14, 2020
1 parent 601ec67 commit 328d6a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/js/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/js/static-filtering-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 328d6a0

Please sign in to comment.