mirror of https://github.com/gorhill/uBlock.git
code review for #3331: support relative paths as per https://github.com/AdguardTeam/AdguardBrowserExtension/issues/917
This commit is contained in:
parent
912582ce4b
commit
8e7ccef14c
|
@ -173,12 +173,12 @@ api.fetchText = function(url, onLoad, onError) {
|
||||||
// Support the seamless loading of sublists.
|
// Support the seamless loading of sublists.
|
||||||
|
|
||||||
api.fetchFilterList = function(mainlistURL, onLoad, onError) {
|
api.fetchFilterList = function(mainlistURL, onLoad, onError) {
|
||||||
var µburi = µBlock.URI,
|
var content = [],
|
||||||
content = [],
|
|
||||||
errored = false,
|
errored = false,
|
||||||
pendingSublistURLs = new Set([ mainlistURL ]),
|
pendingSublistURLs = new Set([ mainlistURL ]),
|
||||||
loadedSublistURLs = new Set(),
|
loadedSublistURLs = new Set(),
|
||||||
mainOriginURL = µburi.originFromURI(mainlistURL);
|
toParsedURL = api.fetchFilterList.toParsedURL,
|
||||||
|
parsedMainURL = toParsedURL(mainlistURL);
|
||||||
|
|
||||||
var onLocalLoadSuccess = function(details) {
|
var onLocalLoadSuccess = function(details) {
|
||||||
if ( errored ) { return; }
|
if ( errored ) { return; }
|
||||||
|
@ -192,21 +192,20 @@ api.fetchFilterList = function(mainlistURL, onLoad, onError) {
|
||||||
content.push(details.content.trim());
|
content.push(details.content.trim());
|
||||||
if ( isSublist ) { content.push('! <<<<<<<< ' + details.url); }
|
if ( isSublist ) { content.push('! <<<<<<<< ' + details.url); }
|
||||||
|
|
||||||
if ( mainOriginURL !== '' ) {
|
if ( parsedMainURL !== undefined ) {
|
||||||
var subOriginURL,
|
var reInclude = /^!#include +(\S+)/gm,
|
||||||
reInclude = /^!#include (\S+)/gm,
|
|
||||||
match = reInclude.exec(details.content);
|
match = reInclude.exec(details.content);
|
||||||
while ( match !== null ) {
|
while ( match !== null ) {
|
||||||
sublistURL = match[1];
|
var parsedSubURL = toParsedURL(match[1]);
|
||||||
subOriginURL = µburi.originFromURI(sublistURL);
|
if ( parsedSubURL === undefined ) {
|
||||||
if ( subOriginURL !== '' && subOriginURL !== mainOriginURL ) {
|
parsedSubURL = toParsedURL(
|
||||||
continue;
|
parsedMainURL.href.replace(/[^/?]+(?:\?.*)?$/, match[1])
|
||||||
|
);
|
||||||
|
if ( parsedSubURL === undefined ) { continue; }
|
||||||
}
|
}
|
||||||
if ( subOriginURL === '' ) {
|
if ( parsedSubURL.origin !== parsedMainURL.origin ) { continue; }
|
||||||
sublistURL = mainOriginURL + '/' + sublistURL;
|
if ( loadedSublistURLs.has(parsedSubURL.href) ) { continue; }
|
||||||
}
|
pendingSublistURLs.add(parsedSubURL.href);
|
||||||
if ( loadedSublistURLs.has(sublistURL) ) { continue; }
|
|
||||||
pendingSublistURLs.add(sublistURL);
|
|
||||||
match = reInclude.exec(details.content);
|
match = reInclude.exec(details.content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -233,6 +232,13 @@ api.fetchFilterList = function(mainlistURL, onLoad, onError) {
|
||||||
this.fetchText(mainlistURL, onLocalLoadSuccess, onLocalLoadError);
|
this.fetchText(mainlistURL, onLocalLoadSuccess, onLocalLoadError);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
api.fetchFilterList.toParsedURL = function(url) {
|
||||||
|
try {
|
||||||
|
return new URL(url);
|
||||||
|
} catch (ex) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
The purpose of the asset source registry is to keep key detail information
|
The purpose of the asset source registry is to keep key detail information
|
||||||
|
|
Loading…
Reference in New Issue