1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-10-08 02:27:12 +02: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:
Raymond Hill 2024-10-05 14:59:43 -04:00
parent 02cba63331
commit 64b2086ba4
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 13 additions and 2 deletions

View File

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

View File

@ -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?:\/\//, '');