mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-01 16:33:06 +01:00
Minor review of redirect-related code
Notably, I finally settled for implicit priority of 0, but now negative priority values are allowed.
This commit is contained in:
parent
a48e986546
commit
26dc7a1490
@ -187,7 +187,7 @@ CodeMirror.defineMode('ubo-static-filtering', function() {
|
||||
/[$,]redirect(-rule)?=$/.test(string.slice(0, pos))
|
||||
) {
|
||||
style = 'value';
|
||||
let end = parser.skipUntil(
|
||||
const end = parser.skipUntil(
|
||||
parserSlot,
|
||||
parser.commentSpan.i,
|
||||
parser.BITComma
|
||||
|
@ -291,11 +291,11 @@ RedirectEngine.prototype.freeze = function() {
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
RedirectEngine.prototype.tokenToURL = function(fctxt, token) {
|
||||
const asDataURI = token.charCodeAt(0) === 0x25 /* '%' */;
|
||||
if ( asDataURI ) {
|
||||
token = token.slice(1);
|
||||
}
|
||||
RedirectEngine.prototype.tokenToURL = function(
|
||||
fctxt,
|
||||
token,
|
||||
asDataURI = false
|
||||
) {
|
||||
const entry = this.resources.get(this.aliases.get(token) || token);
|
||||
if ( entry === undefined ) { return; }
|
||||
this.resourceNameRegister = token;
|
||||
|
@ -1164,13 +1164,15 @@ const Parser = class {
|
||||
|
||||
static parseRedirectValue(arg) {
|
||||
let token = arg.trim();
|
||||
let priority = 10;
|
||||
const match = /:\d+$/.exec(token);
|
||||
let priority = 0;
|
||||
const asDataURI = token.charCodeAt(0) === 0x25 /* '%' */;
|
||||
if ( asDataURI ) { token = token.slice(1); }
|
||||
const match = /:-?\d+$/.exec(token);
|
||||
if ( match !== null ) {
|
||||
token = token.slice(0, match.index);
|
||||
priority = parseInt(token.slice(match.index + 1), 10);
|
||||
}
|
||||
return { token, priority };
|
||||
return { token, priority, asDataURI };
|
||||
}
|
||||
|
||||
static parseQueryPruneValue(arg) {
|
||||
|
@ -4236,12 +4236,13 @@ FilterContainer.prototype.redirectRequest = function(fctxt) {
|
||||
const directives = this.matchAndFetchModifiers(fctxt, 'redirect-rule');
|
||||
// No directive is the most common occurrence.
|
||||
if ( directives === undefined ) { return; }
|
||||
const highest = directives.length - 1;
|
||||
// More than a single directive means more work.
|
||||
if ( directives.length !== 1 ) {
|
||||
if ( highest !== 0 ) {
|
||||
directives.sort(FilterContainer.compareRedirectRequests);
|
||||
}
|
||||
// Redirect to highest-ranked directive
|
||||
const directive = directives[directives.length - 1];
|
||||
const directive = directives[highest];
|
||||
if ( (directive.bits & AllowAction) === 0 ) {
|
||||
const { token } =
|
||||
FilterContainer.parseRedirectRequestValue(directive.modifier);
|
||||
|
Loading…
Reference in New Issue
Block a user