mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-13 10:17:34 +01:00
Fix handling of data:
for filtering purpose in logger
Related issue: - https://github.com/gorhill/uBlock/issues/2469
This commit is contained in:
parent
f677443878
commit
a0ac1b7ee8
3 changed files with 38 additions and 21 deletions
|
@ -1070,6 +1070,7 @@ const reloadTab = function(ev) {
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
const reRFC3986 = /^([^:\/?#]+:)?(\/\/[^\/?#]*)?([^?#]*)(\?[^#]*)?(#.*)?/;
|
const reRFC3986 = /^([^:\/?#]+:)?(\/\/[^\/?#]*)?([^?#]*)(\?[^#]*)?(#.*)?/;
|
||||||
|
const reSchemeOnly = /^[\w-]+:$/;
|
||||||
const staticFilterTypes = {
|
const staticFilterTypes = {
|
||||||
'beacon': 'other',
|
'beacon': 'other',
|
||||||
'doc': 'document',
|
'doc': 'document',
|
||||||
|
@ -1148,12 +1149,16 @@ const reloadTab = function(ev) {
|
||||||
}
|
}
|
||||||
let value = selectValue('select.static.url');
|
let value = selectValue('select.static.url');
|
||||||
if ( value !== '' ) {
|
if ( value !== '' ) {
|
||||||
if ( value.slice(-1) === '/' ) {
|
if ( reSchemeOnly.test(value) ) {
|
||||||
value += '*';
|
value = `|${value}`;
|
||||||
} else if ( /[/?]/.test(value) === false ) {
|
} else {
|
||||||
value += '^';
|
if ( value.endsWith('/') ) {
|
||||||
|
value += '*';
|
||||||
|
} else if ( /[/?]/.test(value) === false ) {
|
||||||
|
value += '^';
|
||||||
|
}
|
||||||
|
value = `||${value}`;
|
||||||
}
|
}
|
||||||
value = '||' + value;
|
|
||||||
}
|
}
|
||||||
filter += value;
|
filter += value;
|
||||||
value = selectValue('select.static.type');
|
value = selectValue('select.static.type');
|
||||||
|
@ -1401,12 +1406,13 @@ const reloadTab = function(ev) {
|
||||||
|
|
||||||
// Build list of candidate URLs
|
// Build list of candidate URLs
|
||||||
const createTargetURLs = function(url) {
|
const createTargetURLs = function(url) {
|
||||||
const urls = [];
|
|
||||||
const matches = reRFC3986.exec(url);
|
const matches = reRFC3986.exec(url);
|
||||||
if ( matches === null || !matches[1] || !matches[2] ) {
|
if ( matches === null ) { return []; }
|
||||||
return urls;
|
if ( typeof matches[2] !== 'string' || matches[2].length === 0 ) {
|
||||||
|
return [ matches[1] ];
|
||||||
}
|
}
|
||||||
// Shortest URL for a valid URL filtering rule
|
// Shortest URL for a valid URL filtering rule
|
||||||
|
const urls = [];
|
||||||
const rootURL = matches[1] + matches[2];
|
const rootURL = matches[1] + matches[2];
|
||||||
urls.unshift(rootURL);
|
urls.unshift(rootURL);
|
||||||
const path = matches[3] || '';
|
const path = matches[3] || '';
|
||||||
|
@ -1587,6 +1593,11 @@ const reloadTab = function(ev) {
|
||||||
const fillDynamicPane = function() {
|
const fillDynamicPane = function() {
|
||||||
if ( targetRow.classList.contains('cosmeticRealm') ) { return; }
|
if ( targetRow.classList.contains('cosmeticRealm') ) { return; }
|
||||||
|
|
||||||
|
// https://github.com/gorhill/uBlock/issues/2469
|
||||||
|
if ( targetURLs.length === 0 || reSchemeOnly.test(targetURLs[0]) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Fill context selector
|
// Fill context selector
|
||||||
let select = selectNode('select.dynamic.origin');
|
let select = selectNode('select.dynamic.origin');
|
||||||
fillOriginSelect(select, targetPageHostname, targetPageDomain);
|
fillOriginSelect(select, targetPageHostname, targetPageDomain);
|
||||||
|
@ -1604,15 +1615,16 @@ const reloadTab = function(ev) {
|
||||||
// Fill entries
|
// Fill entries
|
||||||
const menuEntryTemplate = dialog.querySelector('.dynamic .toolbar .entry');
|
const menuEntryTemplate = dialog.querySelector('.dynamic .toolbar .entry');
|
||||||
const tbody = dialog.querySelector('.dynamic .entries');
|
const tbody = dialog.querySelector('.dynamic .entries');
|
||||||
for ( let i = 0; i < targetURLs.length; i++ ) {
|
for ( const targetURL of targetURLs ) {
|
||||||
const url = targetURLs[i];
|
|
||||||
const menuEntry = menuEntryTemplate.cloneNode(true);
|
const menuEntry = menuEntryTemplate.cloneNode(true);
|
||||||
menuEntry.children[0].setAttribute('data-url', url);
|
menuEntry.children[0].setAttribute('data-url', targetURL);
|
||||||
menuEntry.children[1].textContent = shortenLongString(url, 128);
|
menuEntry.children[1].textContent = shortenLongString(targetURL, 128);
|
||||||
tbody.appendChild(menuEntry);
|
tbody.appendChild(menuEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
colorize();
|
colorize();
|
||||||
|
|
||||||
|
uDom('#modalOverlayContainer [data-pane="dynamic"]').removeClass('hide');
|
||||||
};
|
};
|
||||||
|
|
||||||
const fillOriginSelect = function(select, hostname, domain) {
|
const fillOriginSelect = function(select, hostname, domain) {
|
||||||
|
@ -1682,8 +1694,8 @@ const reloadTab = function(ev) {
|
||||||
case '{{url}}':
|
case '{{url}}':
|
||||||
select = document.createElement('select');
|
select = document.createElement('select');
|
||||||
select.className = 'static url';
|
select.className = 'static url';
|
||||||
for ( let i = 0, n = targetURLs.length; i < n; i++ ) {
|
for ( const targetURL of targetURLs ) {
|
||||||
const value = targetURLs[i].replace(/^[a-z-]+:\/\//, '');
|
const value = targetURL.replace(/^[a-z-]+:\/\//, '');
|
||||||
option = document.createElement('option');
|
option = document.createElement('option');
|
||||||
option.setAttribute('value', value);
|
option.setAttribute('value', value);
|
||||||
option.textContent = shortenLongString(value, 128);
|
option.textContent = shortenLongString(value, 128);
|
||||||
|
@ -1772,7 +1784,11 @@ const reloadTab = function(ev) {
|
||||||
'loggerUI',
|
'loggerUI',
|
||||||
{
|
{
|
||||||
what: 'getDomainNames',
|
what: 'getDomainNames',
|
||||||
targets: [targetURLs[0], targetPageHostname, targetFrameHostname]
|
targets: [
|
||||||
|
targetURLs[0],
|
||||||
|
targetPageHostname,
|
||||||
|
targetFrameHostname
|
||||||
|
]
|
||||||
},
|
},
|
||||||
fillDialog
|
fillDialog
|
||||||
);
|
);
|
||||||
|
|
|
@ -36,11 +36,12 @@ const µb = µBlock;
|
||||||
|
|
||||||
const getDomainNames = function(targets) {
|
const getDomainNames = function(targets) {
|
||||||
const µburi = µb.URI;
|
const µburi = µb.URI;
|
||||||
return targets.map(target =>
|
return targets.map(target => {
|
||||||
target.indexOf('/') !== -1
|
if ( typeof target !== 'string' ) { return ''; }
|
||||||
|
return target.indexOf('/') !== -1
|
||||||
? µburi.domainFromURI(target) || ''
|
? µburi.domainFromURI(target) || ''
|
||||||
: µburi.domainFromHostname(target) || target
|
: µburi.domainFromHostname(target) || target;
|
||||||
);
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
|
@ -106,7 +106,7 @@
|
||||||
<div class="headers">
|
<div class="headers">
|
||||||
 
|
 
|
||||||
<span class="header details" data-pane="details" data-i18n="loggerEntryDetailsHeader"></span>
|
<span class="header details" data-pane="details" data-i18n="loggerEntryDetailsHeader"></span>
|
||||||
<span class="header dynamic" data-pane="dynamic" data-i18n="loggerURLFilteringHeader"></span>
|
<span class="header dynamic hide" data-pane="dynamic" data-i18n="loggerURLFilteringHeader"></span>
|
||||||
<span class="header static" data-pane="static" data-i18n="loggerStaticFilteringHeader"></span>
|
<span class="header static" data-pane="static" data-i18n="loggerStaticFilteringHeader"></span>
|
||||||
<span class="tools"><span class="fa-icon reload">refresh</span> <span class="fa-icon picker">eye-dropper</span></span>
|
<span class="tools"><span class="fa-icon reload">refresh</span> <span class="fa-icon picker">eye-dropper</span></span>
|
||||||
</div>
|
</div>
|
||||||
|
@ -121,7 +121,7 @@
|
||||||
<div><span data-i18n="loggerEntryDetailsType"></span><span></span></div>
|
<div><span data-i18n="loggerEntryDetailsType"></span><span></span></div>
|
||||||
<div><span data-i18n="loggerEntryDetailsURL"></span><span></span></div>
|
<div><span data-i18n="loggerEntryDetailsURL"></span><span></span></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="pane dynamic" data-pane="dynamic">
|
<div class="pane dynamic hide" data-pane="dynamic">
|
||||||
<div class="toolbar row">
|
<div class="toolbar row">
|
||||||
<span><span id="saveRules" class="fa-icon">lock</span></span>
|
<span><span id="saveRules" class="fa-icon">lock</span></span>
|
||||||
<span>
|
<span>
|
||||||
|
|
Loading…
Reference in a new issue