Skip to content

Commit

Permalink
Ignore pseudo-elements when querying selectors in element picker
Browse files Browse the repository at this point in the history
Related issue:
- #2515
  • Loading branch information
gorhill committed Jul 26, 2019
1 parent aaee898 commit 8d136ec
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/js/scriptlets/element-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ const filtersFrom = function(x, y) {
const filterToDOMInterface = (( ) => {
const reHnAnchorPrefix = '^[\\w-]+://(?:[^/?#]+\\.)?';
const reCaret = '(?:[^%.0-9a-z_-]|$)';
const rePseudoElements = /::?(?:after|before)$/;

// Net filters: we need to lookup manually -- translating into a foolproof
// CSS selector is just not possible.
Expand Down Expand Up @@ -795,11 +796,16 @@ const filterToDOMInterface = (( ) => {
// https://github.com/uBlockOrigin/uBlock-issues/issues/389
// Test filter using comma-separated list to better detect invalid CSS
// selectors.
//
// https://github.com/gorhill/uBlock/issues/2515
// Remove trailing pseudo-element when querying.
const fromPlainCosmeticFilter = function(raw) {
let elems;
try {
document.documentElement.matches(`${raw},\na`);
elems = document.querySelectorAll(raw);
elems = document.querySelectorAll(
raw.replace(rePseudoElements, '')
);
}
catch (e) {
return;
Expand All @@ -814,21 +820,25 @@ const filterToDOMInterface = (( ) => {

// https://github.com/gorhill/uBlock/issues/1772
// Handle procedural cosmetic filters.
//
// https://github.com/gorhill/uBlock/issues/2515
// Remove trailing pseudo-element when querying.
const fromCompiledCosmeticFilter = function(raw) {
if ( typeof raw !== 'string' ) { return; }
let o;
let elems;
try {
o = JSON.parse(raw);
const o = JSON.parse(raw);
if ( o.style ) {
elems = document.querySelectorAll(
o.style[0].replace(rePseudoElements, '')
);
lastAction = o.style[0] + ' {' + o.style[1] + '}';
} else if ( o.tasks ) {
elems = vAPI.domFilterer.createProceduralFilter(o).exec();
}
} catch(ex) {
return;
}
let elems;
if ( o.style ) {
elems = document.querySelectorAll(o.style[0]);
lastAction = o.style[0] + ' {' + o.style[1] + '}';
} else if ( o.tasks ) {
elems = vAPI.domFilterer.createProceduralFilter(o).exec();
}
if ( !elems ) { return; }
const out = [];
for ( const elem of elems ) {
Expand Down

3 comments on commit 8d136ec

@uBlock-user
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thefreedictionary.com##li > [href^="//www.freethesaurus.com/"]::before:style(display: none !important) doesn't appear in the logger even though it's a valid styling filter.

@gorhill
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a regression from uBlockOrigin/uBlock-issues#627

@uBlock-user
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought so, as thefreedictionary.com##li > [href^="//www.freethesaurus.com/"]::before appears as expected.

Please sign in to comment.