Skip to content

Commit

Permalink
code review for #3331: support relative paths as per AdguardTeam/Adgu…
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Dec 15, 2017
1 parent 912582c commit 8e7ccef
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/js/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ api.fetchText = function(url, onLoad, onError) {
// Support the seamless loading of sublists.

api.fetchFilterList = function(mainlistURL, onLoad, onError) {
var µburi = µBlock.URI,
content = [],
var content = [],
errored = false,
pendingSublistURLs = new Set([ mainlistURL ]),
loadedSublistURLs = new Set(),
mainOriginURL = µburi.originFromURI(mainlistURL);
toParsedURL = api.fetchFilterList.toParsedURL,
parsedMainURL = toParsedURL(mainlistURL);

var onLocalLoadSuccess = function(details) {
if ( errored ) { return; }
Expand All @@ -192,21 +192,20 @@ api.fetchFilterList = function(mainlistURL, onLoad, onError) {
content.push(details.content.trim());
if ( isSublist ) { content.push('! <<<<<<<< ' + details.url); }

if ( mainOriginURL !== '' ) {
var subOriginURL,
reInclude = /^!#include (\S+)/gm,
if ( parsedMainURL !== undefined ) {
var reInclude = /^!#include +(\S+)/gm,
match = reInclude.exec(details.content);
while ( match !== null ) {
sublistURL = match[1];
subOriginURL = µburi.originFromURI(sublistURL);
if ( subOriginURL !== '' && subOriginURL !== mainOriginURL ) {
continue;
var parsedSubURL = toParsedURL(match[1]);
if ( parsedSubURL === undefined ) {
parsedSubURL = toParsedURL(
parsedMainURL.href.replace(/[^/?]+(?:\?.*)?$/, match[1])
);
if ( parsedSubURL === undefined ) { continue; }
}
if ( subOriginURL === '' ) {
sublistURL = mainOriginURL + '/' + sublistURL;
}
if ( loadedSublistURLs.has(sublistURL) ) { continue; }
pendingSublistURLs.add(sublistURL);
if ( parsedSubURL.origin !== parsedMainURL.origin ) { continue; }
if ( loadedSublistURLs.has(parsedSubURL.href) ) { continue; }
pendingSublistURLs.add(parsedSubURL.href);
match = reInclude.exec(details.content);
}
}
Expand All @@ -233,6 +232,13 @@ api.fetchFilterList = function(mainlistURL, onLoad, onError) {
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
Expand Down

0 comments on commit 8e7ccef

Please sign in to comment.