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:
Raymond Hill 2020-12-02 08:18:55 -05:00
parent a48e986546
commit 26dc7a1490
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
4 changed files with 14 additions and 11 deletions

View File

@ -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

View File

@ -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;

View File

@ -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) {

View File

@ -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);