1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-15 15:32:28 +02:00

Properly handle instances of #?# or #$# in picker

Related feedback:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1363#issuecomment-734957406
This commit is contained in:
Raymond Hill 2020-11-29 11:31:20 -05:00
parent d1895d4749
commit 40a7c47bfc
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 10 additions and 6 deletions

View File

@ -45,6 +45,8 @@ const svgOcean = svgRoot.children[0];
const svgIslands = svgRoot.children[1]; const svgIslands = svgRoot.children[1];
const NoPaths = 'M0 0'; const NoPaths = 'M0 0';
const reCosmeticAnchor = /^#[$?]?#/;
const epickerId = (( ) => { const epickerId = (( ) => {
const url = new URL(self.location.href); const url = new URL(self.location.href);
if ( url.searchParams.has('zap') ) { if ( url.searchParams.has('zap') ) {
@ -144,7 +146,7 @@ const userFilterFromCandidate = function(filter) {
const hn = vAPI.hostnameFromURI(docURL.href); const hn = vAPI.hostnameFromURI(docURL.href);
// Cosmetic filter? // Cosmetic filter?
if ( filter.startsWith('##') ) { if ( reCosmeticAnchor.test(filter) ) {
return hn + filter; return hn + filter;
} }
@ -460,7 +462,7 @@ const onCandidateChanged = function() {
vAPI.MessagingConnection.sendTo(epickerConnectionId, { vAPI.MessagingConnection.sendTo(epickerConnectionId, {
what: 'dialogSetFilter', what: 'dialogSetFilter',
filter, filter,
compiled: filter.startsWith('##') compiled: reCosmeticAnchor.test(filter)
? staticFilteringParser.result.compiled ? staticFilteringParser.result.compiled
: undefined, : undefined,
}); });
@ -487,13 +489,13 @@ const onCreateClicked = function() {
autoComment: true, autoComment: true,
filters: filter, filters: filter,
docURL: docURL.href, docURL: docURL.href,
killCache: /^#[$?]?#/.test(candidate) === false, killCache: reCosmeticAnchor.test(candidate) === false,
}); });
} }
vAPI.MessagingConnection.sendTo(epickerConnectionId, { vAPI.MessagingConnection.sendTo(epickerConnectionId, {
what: 'dialogCreate', what: 'dialogCreate',
filter: candidate, filter: candidate,
compiled: candidate.startsWith('##') compiled: reCosmeticAnchor.test(candidate)
? staticFilteringParser.result.compiled ? staticFilteringParser.result.compiled
: undefined, : undefined,
}); });

View File

@ -38,6 +38,8 @@ if ( pickerRoot !== null ) { return; }
let pickerBootArgs; let pickerBootArgs;
const reCosmeticAnchor = /^#[$?]?#/;
const netFilterCandidates = []; const netFilterCandidates = [];
const cosmeticFilterCandidates = []; const cosmeticFilterCandidates = [];
@ -739,7 +741,7 @@ const filterToDOMInterface = (( ) => {
return; return;
} }
lastFilter = filter; lastFilter = filter;
if ( filter.startsWith('##') === false ) { if ( reCosmeticAnchor.test(filter) === false ) {
lastResultset = fromNetworkFilter(filter); lastResultset = fromNetworkFilter(filter);
if ( previewing ) { apply(); } if ( previewing ) { apply(); }
return lastResultset; return lastResultset;
@ -789,7 +791,7 @@ const filterToDOMInterface = (( ) => {
return unapply(); return unapply();
} }
if ( Array.isArray(lastResultset) === false ) { return; } if ( Array.isArray(lastResultset) === false ) { return; }
if ( permanent === false || lastFilter.startsWith('##') === false ) { if ( permanent === false || reCosmeticAnchor.test(lastFilter) === false ) {
return apply(); return apply();
} }
if ( vAPI.domFilterer instanceof Object === false ) { return; } if ( vAPI.domFilterer instanceof Object === false ) { return; }