Skip to content

Commit 8f81833

Browse files
committed
Classify generic cosmetic filters with comma as highly generic
Related discussion: https://old.reddit.com/r/uBlockOrigin/comments/1d3ezoy/
1 parent 82a3992 commit 8f81833

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

src/js/cosmetic-filtering.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,12 @@
1919
Home: https://github.com/gorhill/uBlock
2020
*/
2121

22-
'use strict';
23-
2422
/******************************************************************************/
2523

26-
import logger from './logger.js';
27-
import µb from './background.js';
28-
2924
import { MRUCache } from './mrucache.js';
3025
import { StaticExtFilteringHostnameDB } from './static-ext-filtering-db.js';
26+
import logger from './logger.js';
27+
import µb from './background.js';
3128

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

169166
const keyFromSelector = selector => {
167+
let matches = reSimplestSelector.exec(selector);
168+
if ( matches !== null ) { return matches[0]; }
170169
let key = '';
171-
let matches = rePlainSelector.exec(selector);
170+
matches = rePlainSelector.exec(selector);
172171
if ( matches !== null ) {
173172
key = matches[0];
174173
} else {
175174
matches = rePlainSelectorEx.exec(selector);
176175
if ( matches === null ) { return; }
177176
key = matches[1] || matches[2];
178177
}
178+
if ( selector.includes(',') ) { return; }
179179
if ( key.includes('\\') === false ) { return key; }
180180
matches = rePlainSelectorEscaped.exec(selector);
181181
if ( matches === null ) { return; }
@@ -198,8 +198,9 @@ const keyFromSelector = selector => {
198198
}
199199
};
200200

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

0 commit comments

Comments
 (0)