Skip to content

Commit

Permalink
Classify generic cosmetic filters with comma as highly generic
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Jun 1, 2024
1 parent 82a3992 commit 8f81833
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/js/cosmetic-filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@
Home: https://github.com/gorhill/uBlock
*/

'use strict';

/******************************************************************************/

import logger from './logger.js';
import µb from './background.js';

import { MRUCache } from './mrucache.js';
import { StaticExtFilteringHostnameDB } from './static-ext-filtering-db.js';
import logger from './logger.js';
import µb from './background.js';

/******************************************************************************/
/******************************************************************************/
Expand Down Expand Up @@ -167,15 +164,18 @@ const hashFromStr = (type, s) => {
// It's an uncommon case, so it's best to unescape only when needed.

const keyFromSelector = selector => {
let matches = reSimplestSelector.exec(selector);
if ( matches !== null ) { return matches[0]; }
let key = '';
let matches = rePlainSelector.exec(selector);
matches = rePlainSelector.exec(selector);
if ( matches !== null ) {
key = matches[0];
} else {
matches = rePlainSelectorEx.exec(selector);
if ( matches === null ) { return; }
key = matches[1] || matches[2];
}
if ( selector.includes(',') ) { return; }
if ( key.includes('\\') === false ) { return key; }
matches = rePlainSelectorEscaped.exec(selector);
if ( matches === null ) { return; }
Expand All @@ -198,8 +198,9 @@ const keyFromSelector = selector => {
}
};

const reSimplestSelector = /^[#.][\w-]+$/;
const rePlainSelector = /^[#.][\w\\-]+/;
const rePlainSelectorEx = /^[^#.\[(]+([#.][\w-]+)|([#.][\w-]+)$/;
const rePlainSelectorEx = /^[^#.[(]+([#.][\w-]+)|([#.][\w-]+)$/;
const rePlainSelectorEscaped = /^[#.](?:\\[0-9A-Fa-f]+ |\\.|\w|-)+/;
const reEscapeSequence = /\\([0-9A-Fa-f]+ |.)/g;

Expand Down

0 comments on commit 8f81833

Please sign in to comment.