From d5903904314b15e84a5f5ad55ab8b370412929ee Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Wed, 14 Jun 2023 10:19:48 -0400 Subject: [PATCH] [mv3] Properly compiled complex generic cosmetic filters Related issue: - https://github.com/uBlockOrigin/uBOL-issues/issues/47 --- src/js/static-dnr-filtering.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/js/static-dnr-filtering.js b/src/js/static-dnr-filtering.js index c72461fb8..27194c6dc 100644 --- a/src/js/static-dnr-filtering.js +++ b/src/js/static-dnr-filtering.js @@ -53,16 +53,21 @@ const hashFromStr = (type, s) => { // dependencies const rePlainSelector = /^[#.][\w\\-]+/; +const rePlainSelectorEx = /^[^#.\[(]+([#.][\w-]+)|([#.][\w-]+)$/; const rePlainSelectorEscaped = /^[#.](?:\\[0-9A-Fa-f]+ |\\.|\w|-)+/; const reEscapeSequence = /\\([0-9A-Fa-f]+ |.)/g; const keyFromSelector = selector => { + let key = ''; let matches = rePlainSelector.exec(selector); - if ( matches === null ) { return; } - let key = matches[0]; - if ( key.indexOf('\\') === -1 ) { - return key; + if ( matches ) { + key = matches[0]; + } else { + matches = rePlainSelectorEx.exec(selector); + if ( matches === null ) { return; } + key = matches[1] || matches[2]; } + if ( key.indexOf('\\') === -1 ) { return key; } matches = rePlainSelectorEscaped.exec(selector); if ( matches === null ) { return; } key = '';