From 8f81833efc9f99a8f461db3e37a6b49ccbd3ffd8 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sat, 1 Jun 2024 10:46:18 -0400 Subject: [PATCH] Classify generic cosmetic filters with comma as highly generic Related discussion: https://old.reddit.com/r/uBlockOrigin/comments/1d3ezoy/ --- src/js/cosmetic-filtering.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/js/cosmetic-filtering.js b/src/js/cosmetic-filtering.js index 9ce1bf48a..9a078095c 100644 --- a/src/js/cosmetic-filtering.js +++ b/src/js/cosmetic-filtering.js @@ -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'; /******************************************************************************/ /******************************************************************************/ @@ -167,8 +164,10 @@ 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 { @@ -176,6 +175,7 @@ const keyFromSelector = 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; } @@ -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;