From 40a7c47bfcedcb54fa6d0eeac2e32ecb4117baec Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 29 Nov 2020 11:31:20 -0500 Subject: [PATCH] Properly handle instances of `#?#` or `#$#` in picker Related feedback: - https://github.com/uBlockOrigin/uBlock-issues/issues/1363#issuecomment-734957406 --- src/js/epicker-ui.js | 10 ++++++---- src/js/scriptlets/epicker.js | 6 ++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/js/epicker-ui.js b/src/js/epicker-ui.js index 84a9a963a..7c8df0974 100644 --- a/src/js/epicker-ui.js +++ b/src/js/epicker-ui.js @@ -45,6 +45,8 @@ const svgOcean = svgRoot.children[0]; const svgIslands = svgRoot.children[1]; const NoPaths = 'M0 0'; +const reCosmeticAnchor = /^#[$?]?#/; + const epickerId = (( ) => { const url = new URL(self.location.href); if ( url.searchParams.has('zap') ) { @@ -144,7 +146,7 @@ const userFilterFromCandidate = function(filter) { const hn = vAPI.hostnameFromURI(docURL.href); // Cosmetic filter? - if ( filter.startsWith('##') ) { + if ( reCosmeticAnchor.test(filter) ) { return hn + filter; } @@ -460,7 +462,7 @@ const onCandidateChanged = function() { vAPI.MessagingConnection.sendTo(epickerConnectionId, { what: 'dialogSetFilter', filter, - compiled: filter.startsWith('##') + compiled: reCosmeticAnchor.test(filter) ? staticFilteringParser.result.compiled : undefined, }); @@ -487,13 +489,13 @@ const onCreateClicked = function() { autoComment: true, filters: filter, docURL: docURL.href, - killCache: /^#[$?]?#/.test(candidate) === false, + killCache: reCosmeticAnchor.test(candidate) === false, }); } vAPI.MessagingConnection.sendTo(epickerConnectionId, { what: 'dialogCreate', filter: candidate, - compiled: candidate.startsWith('##') + compiled: reCosmeticAnchor.test(candidate) ? staticFilteringParser.result.compiled : undefined, }); diff --git a/src/js/scriptlets/epicker.js b/src/js/scriptlets/epicker.js index 02f625225..ae1e70e2a 100644 --- a/src/js/scriptlets/epicker.js +++ b/src/js/scriptlets/epicker.js @@ -38,6 +38,8 @@ if ( pickerRoot !== null ) { return; } let pickerBootArgs; +const reCosmeticAnchor = /^#[$?]?#/; + const netFilterCandidates = []; const cosmeticFilterCandidates = []; @@ -739,7 +741,7 @@ const filterToDOMInterface = (( ) => { return; } lastFilter = filter; - if ( filter.startsWith('##') === false ) { + if ( reCosmeticAnchor.test(filter) === false ) { lastResultset = fromNetworkFilter(filter); if ( previewing ) { apply(); } return lastResultset; @@ -789,7 +791,7 @@ const filterToDOMInterface = (( ) => { return unapply(); } if ( Array.isArray(lastResultset) === false ) { return; } - if ( permanent === false || lastFilter.startsWith('##') === false ) { + if ( permanent === false || reCosmeticAnchor.test(lastFilter) === false ) { return apply(); } if ( vAPI.domFilterer instanceof Object === false ) { return; }