Skip to content

Commit

Permalink
Fixed URLSearchParams spaces (x sign) bug
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinRoebert committed Nov 11, 2023
1 parent 14a0832 commit 92e43b7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clearurls.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function removeFieldsFormURL(provider, pureUrl, quiet = false, request = null) {

let finalURL = domain;

if (fields.toString() !== "") finalURL += "?" + fields.toString();
if (fields.toString() !== "") finalURL += "?" + urlSearchParamsToString(fields);
if (fragments.toString() !== "") finalURL += "#" + fragments.toString();

url = finalURL.replace(new RegExp("\\?&"), "?").replace(new RegExp("#&"), "#");
Expand Down
18 changes: 18 additions & 0 deletions core_js/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,21 @@ async function sha256(message) {
function randomASCII(len) {
return [...Array(len)].map(() => (~~(Math.random() * 36)).toString(36)).join('');
}

/**
* Returns an URLSearchParams as string.
* Does handle spaces correctly.
*/
function urlSearchParamsToString(searchParams) {
const rtn = []

searchParams.forEach((value, key) => {
if (value) {
rtn.push(key + '=' + value)
} else {
rtn.push(key)
}
})

return rtn.join('&')
}

0 comments on commit 92e43b7

Please sign in to comment.