Skip to content

Commit 92e43b7

Browse files
committed
Fixed URLSearchParams spaces (x sign) bug
See also https://gitlab.com/ClearURLs/ClearUrls/-/merge_requests/108
1 parent 14a0832 commit 92e43b7

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

clearurls.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ function removeFieldsFormURL(provider, pureUrl, quiet = false, request = null) {
152152

153153
let finalURL = domain;
154154

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

158158
url = finalURL.replace(new RegExp("\\?&"), "?").replace(new RegExp("#&"), "#");

core_js/tools.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,21 @@ async function sha256(message) {
337337
function randomASCII(len) {
338338
return [...Array(len)].map(() => (~~(Math.random() * 36)).toString(36)).join('');
339339
}
340+
341+
/**
342+
* Returns an URLSearchParams as string.
343+
* Does handle spaces correctly.
344+
*/
345+
function urlSearchParamsToString(searchParams) {
346+
const rtn = []
347+
348+
searchParams.forEach((value, key) => {
349+
if (value) {
350+
rtn.push(key + '=' + value)
351+
} else {
352+
rtn.push(key)
353+
}
354+
})
355+
356+
return rtn.join('&')
357+
}

0 commit comments

Comments
 (0)