Skip to content

Commit

Permalink
Add ability to lookup parameter name in urlskip=
Browse files Browse the repository at this point in the history
Relate case:
uBlockOrigin/uBlock-issues#3206 (comment)

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).
  • Loading branch information
gorhill committed Oct 5, 2024
1 parent 02cba63 commit 64b2086
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/js/static-filtering-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
13 changes: 12 additions & 1 deletion src/js/static-net-filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ') ) {
Expand All @@ -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?:\/\//, '');
Expand Down

0 comments on commit 64b2086

Please sign in to comment.