From 01eebffc1fd133f4f72f886551e79ba4bfc3bb24 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 11 Oct 2024 08:54:50 -0400 Subject: [PATCH] Add `-uricomponent` to `urlskip=` option To unescape URI-encoded characters. Related discussion: https://github.com/uBlockOrigin/uBlock-issues/issues/3206#issuecomment-2406479971 --- src/js/static-net-filtering.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index 6bd9fe00cd83f..92fc51b33cb2a 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -5406,6 +5406,8 @@ StaticNetFilteringEngine.prototype.transformRequest = function(fctxt, out = []) * * `-base64`: decode the current string as a base64-encoded string. * + * `-uricomponent`: decode the current string as a URI component string. + * * At any given step, the currently extracted string may not necessarily be * a valid URL, and more transformation steps may be needed to obtain a valid * URL once all the steps are applied. @@ -5470,10 +5472,18 @@ function urlSkip(directive, urlin, steps) { urlout = `https://${s}`; continue; } - // Decode base64 - if ( c0 === 0x2D && step === '-base64' ) { - urlout = self.atob(urlin); - continue; + // Decode + if ( c0 === 0x2D ) { + // Base64 + if ( step === '-base64' ) { + urlout = self.atob(urlin); + continue; + } + // URI component + if ( step === '-uricomponent' ) { + urlout = self.decodeURIComponent(urlin); + continue; + } } // Regex extraction from first capture group if ( c0 === 0x2F ) { // /