mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-21 18:02:34 +01:00
Add ability to lookup parameter name in urlskip=
Relate case: https://github.com/uBlockOrigin/uBlock-issues/issues/3206#issuecomment-2395121619 Newly supported step: `&i`, meant to lookup a parameter's name at position `i` (1-based). The parameter name will be used as the URL (whereas `?` is meant to lookup a parameter's value).
This commit is contained in:
parent
02cba63331
commit
64b2086ba4
@ -1531,7 +1531,7 @@ export class AstFilterParser {
|
||||
break;
|
||||
}
|
||||
const value = this.getNetOptionValue(NODE_TYPE_NET_OPTION_NAME_URLSKIP);
|
||||
if ( value.startsWith('?') === false || value.length < 2 ) {
|
||||
if ( value.length < 2 ) {
|
||||
this.astError = AST_ERROR_OPTION_BADVALUE;
|
||||
realBad = true;
|
||||
}
|
||||
|
@ -5411,8 +5411,9 @@ function urlSkip(urlin, steps) {
|
||||
try {
|
||||
let urlout;
|
||||
for ( const step of steps ) {
|
||||
const c0 = step.charCodeAt(0);
|
||||
// Extract from URL parameter
|
||||
if ( step.startsWith('?') ) {
|
||||
if ( c0 === 0x3F ) { /* ? */
|
||||
urlout = (new URL(urlin)).searchParams.get(step.slice(1));
|
||||
if ( urlout === null ) { return; }
|
||||
if ( urlout.includes(' ') ) {
|
||||
@ -5421,6 +5422,16 @@ function urlSkip(urlin, steps) {
|
||||
urlin = urlout;
|
||||
continue;
|
||||
}
|
||||
// Extract from URL parameter name at position i
|
||||
if ( c0 === 0x26 ) { /* & */
|
||||
const i = (parseInt(step.slice(1)) || 0) - 1;
|
||||
if ( i < 0 ) { return; }
|
||||
const url = new URL(urlin);
|
||||
if ( i >= url.searchParams.size ) { return; }
|
||||
const params = Array.from(url.searchParams.keys());
|
||||
urlin = urlout = decodeURIComponent(params[i]);
|
||||
continue;
|
||||
}
|
||||
// Enforce https
|
||||
if ( step === '+https' ) {
|
||||
const s = urlin.replace(/^https?:\/\//, '');
|
||||
|
Loading…
Reference in New Issue
Block a user