Fixed URLSearchParams spaces (x sign) bug

See also https://gitlab.com/ClearURLs/ClearUrls/-/merge_requests/108
This commit is contained in:
Kevin R
2023-11-11 15:54:08 +01:00
parent 14a0832973
commit 92e43b7f61
2 changed files with 19 additions and 1 deletions

View File

@@ -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('&')
}