make "none" a reserved "redirect=" keyword (see deefe87555)

This commit is contained in:
Raymond Hill 2018-10-31 19:34:54 -03:00
parent 90089d7d8c
commit 23cd2e1d4a
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 26 additions and 18 deletions

View File

@ -28,7 +28,7 @@
/******************************************************************************/ /******************************************************************************/
/******************************************************************************/ /******************************************************************************/
var warResolve = (function() { const warResolve = (function() {
var warPairs = []; var warPairs = [];
var onPairsReady = function() { var onPairsReady = function() {
@ -76,12 +76,12 @@ var warResolve = (function() {
// Do not redirect to a WAR if the platform suffers from spurious redirect // Do not redirect to a WAR if the platform suffers from spurious redirect
// conflicts, and the request to redirect is not `https:`. // conflicts, and the request to redirect is not `https:`.
// This special handling code can removed once the Chromium issue is fixed. // This special handling code can removed once the Chromium issue is fixed.
var suffersSpuriousRedirectConflicts = vAPI.webextFlavor.soup.has('chromium'); const suffersSpuriousRedirectConflicts = vAPI.webextFlavor.soup.has('chromium');
/******************************************************************************/ /******************************************************************************/
/******************************************************************************/ /******************************************************************************/
var RedirectEntry = function() { const RedirectEntry = function() {
this.mime = ''; this.mime = '';
this.data = ''; this.data = '';
this.warURL = undefined; this.warURL = undefined;
@ -153,7 +153,7 @@ RedirectEntry.fromSelfie = function(selfie) {
/******************************************************************************/ /******************************************************************************/
/******************************************************************************/ /******************************************************************************/
var RedirectEngine = function() { const RedirectEngine = function() {
this.resources = new Map(); this.resources = new Map();
this.reset(); this.reset();
this.resourceNameRegister = ''; this.resourceNameRegister = '';
@ -219,9 +219,9 @@ RedirectEngine.prototype.lookup = function(context) {
}; };
RedirectEngine.prototype.lookupToken = function(entries, reqURL) { RedirectEngine.prototype.lookupToken = function(entries, reqURL) {
var j = entries.length, entry; let j = entries.length;
while ( j-- ) { while ( j-- ) {
entry = entries[j]; let entry = entries[j];
if ( entry.pat instanceof RegExp === false ) { if ( entry.pat instanceof RegExp === false ) {
entry.pat = new RegExp(entry.pat, 'i'); entry.pat = new RegExp(entry.pat, 'i');
} }
@ -235,9 +235,9 @@ RedirectEngine.prototype.lookupToken = function(entries, reqURL) {
/******************************************************************************/ /******************************************************************************/
RedirectEngine.prototype.toURL = function(context) { RedirectEngine.prototype.toURL = function(context) {
var token = this.lookup(context); let token = this.lookup(context);
if ( token === undefined ) { return; } if ( token === undefined ) { return; }
var entry = this.resources.get(token); let entry = this.resources.get(token);
if ( entry !== undefined ) { if ( entry !== undefined ) {
return entry.toURL(context); return entry.toURL(context);
} }
@ -457,24 +457,26 @@ RedirectEngine.prototype.resourceContentFromName = function(name, mime) {
// TODO: combine same key-redirect pairs into a single regex. // TODO: combine same key-redirect pairs into a single regex.
// https://github.com/uBlockOrigin/uAssets/commit/deefe875551197d655f79cb540e62dfc17c95f42
// Consider 'none' a reserved keyword, to be used to disable redirection.
RedirectEngine.prototype.resourcesFromString = function(text) { RedirectEngine.prototype.resourcesFromString = function(text) {
var line, fields, encoded, let fields, encoded,
reNonEmptyLine = /\S/, reNonEmptyLine = /\S/,
lineIter = new µBlock.LineIterator(text); lineIter = new µBlock.LineIterator(text);
this.resources = new Map(); this.resources = new Map();
while ( lineIter.eot() === false ) { while ( lineIter.eot() === false ) {
line = lineIter.next(); let line = lineIter.next();
if ( line.startsWith('#') ) { continue; } if ( line.startsWith('#') ) { continue; }
if ( fields === undefined ) { if ( fields === undefined ) {
fields = line.trim().split(/\s+/); let head = line.trim().split(/\s+/);
if ( fields.length === 2 ) { if ( head.length !== 2 ) { continue; }
encoded = fields[1].indexOf(';') !== -1; if ( head[0] === 'none' ) { continue; }
} else { encoded = head[1].indexOf(';') !== -1;
fields = undefined; fields = head;
}
continue; continue;
} }
@ -484,14 +486,20 @@ RedirectEngine.prototype.resourcesFromString = function(text) {
} }
// No more data, add the resource. // No more data, add the resource.
this.resources.set(fields[0], RedirectEntry.fromFields(fields[1], fields.slice(2))); this.resources.set(
fields[0],
RedirectEntry.fromFields(fields[1], fields.slice(2))
);
fields = undefined; fields = undefined;
} }
// Process pending resource data. // Process pending resource data.
if ( fields !== undefined ) { if ( fields !== undefined ) {
this.resources.set(fields[0], RedirectEntry.fromFields(fields[1], fields.slice(2))); this.resources.set(
fields[0],
RedirectEntry.fromFields(fields[1], fields.slice(2))
);
} }
warResolve(); warResolve();