Skip to content

Commit

Permalink
Limit recursion when parsing URL in document-blocked page
Browse files Browse the repository at this point in the history
  • Loading branch information
kevintde committed Jul 18, 2021
1 parent 0bcb766 commit aede770
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/js/main-blocked.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,31 +87,32 @@ uDom('.what').text(details.url);
return s;
};

const renderParams = function(parentNode, rawURL) {
// https://github.com/uBlockOrigin/uBlock-issues/issues/1649
// Limit recursion.
const renderParams = function(parentNode, rawURL, depth = 0) {
const a = document.createElement('a');
a.href = rawURL;
if ( a.search.length === 0 ) { return false; }

const pos = rawURL.indexOf('?');
let pos = rawURL.indexOf('?');
const li = liFromParam(
vAPI.i18n('mainBlockedNoParamsPrompt'),
vAPI.i18n('docblockedNoParamsPrompt'),
rawURL.slice(0, pos)
);
parentNode.appendChild(li);

const params = a.search.slice(1).split('&');
for ( let i = 0; i < params.length; i++ ) {
const param = params[i];
for ( const param of params ) {
let pos = param.indexOf('=');
if ( pos === -1 ) {
pos = param.length;
}
const name = safeDecodeURIComponent(param.slice(0, pos));
const value = safeDecodeURIComponent(param.slice(pos + 1));
const li = liFromParam(name, value);
if ( reURL.test(value) ) {
if ( depth < 2 && reURL.test(value) ) {
const ul = document.createElement('ul');
renderParams(ul, value);
renderParams(ul, value, depth + 1);
li.appendChild(ul);
}
parentNode.appendChild(li);
Expand Down

0 comments on commit aede770

Please sign in to comment.