1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-04 10:09:38 +02:00

Avoid parsing query parameters with URLSearchParams

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1717
This commit is contained in:
Raymond Hill 2021-09-12 12:17:46 -04:00
parent 670c5f1a7b
commit a3a66d0e31
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -4366,9 +4366,20 @@ FilterContainer.prototype.filterQuery = function(fctxt) {
if ( qpos === -1 ) { return; }
let hpos = url.indexOf('#', qpos + 1);
if ( hpos === -1 ) { hpos = url.length; }
const params = new Map(
new URLSearchParams(url.slice(qpos + 1, hpos))
);
const params = new Map();
const query = url.slice(qpos + 1, hpos);
for ( let i = 0; i < query.length; ) {
let pos = query.indexOf('&', i);
if ( pos === -1 ) { pos = query.length; }
const kv = query.slice(i, pos);
i = pos + 1;
pos = kv.indexOf('=');
if ( pos !== -1 ) {
params.set(kv.slice(0, pos), kv.slice(pos + 1));
} else {
params.set(kv, '');
}
}
const inParamCount = params.size;
const out = [];
for ( const directive of directives ) {
@ -4405,7 +4416,10 @@ FilterContainer.prototype.filterQuery = function(fctxt) {
}
if ( re === undefined ) { continue; }
let filtered = false;
for ( const [ key, value ] of params ) {
for ( const [ key, raw ] of params ) {
let value = raw;
try { value = decodeURIComponent(value); }
catch(ex) { }
if ( re.test(`${key}=${value}`) === not ) { continue; }
if ( isException === false ) { params.delete(key); }
filtered = true;
@ -4419,7 +4433,7 @@ FilterContainer.prototype.filterQuery = function(fctxt) {
fctxt.redirectURL = url.slice(0, qpos);
if ( params.size !== 0 ) {
fctxt.redirectURL += '?' + Array.from(params).map(a =>
a[1] === '' ? a[0] : `${a[0]}=${encodeURIComponent(a[1])}`
a[1] === '' ? a[0] : `${a[0]}=${a[1]}`
).join('&');
}
if ( hpos !== url.length ) {