Add `-uricomponent` to `urlskip=` option

To unescape URI-encoded characters.

Related discussion:
https://github.com/uBlockOrigin/uBlock-issues/issues/3206#issuecomment-2406479971
This commit is contained in:
Raymond Hill 2024-10-11 08:54:50 -04:00
parent 4d982d9972
commit 01eebffc1f
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 14 additions and 4 deletions

View File

@ -5406,6 +5406,8 @@ StaticNetFilteringEngine.prototype.transformRequest = function(fctxt, out = [])
* *
* `-base64`: decode the current string as a base64-encoded string. * `-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 * 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 * a valid URL, and more transformation steps may be needed to obtain a valid
* URL once all the steps are applied. * URL once all the steps are applied.
@ -5470,10 +5472,18 @@ function urlSkip(directive, urlin, steps) {
urlout = `https://${s}`; urlout = `https://${s}`;
continue; continue;
} }
// Decode base64 // Decode
if ( c0 === 0x2D && step === '-base64' ) { if ( c0 === 0x2D ) {
urlout = self.atob(urlin); // Base64
continue; if ( step === '-base64' ) {
urlout = self.atob(urlin);
continue;
}
// URI component
if ( step === '-uricomponent' ) {
urlout = self.decodeURIComponent(urlin);
continue;
}
} }
// Regex extraction from first capture group // Regex extraction from first capture group
if ( c0 === 0x2F ) { // / if ( c0 === 0x2F ) { // /