FIX: Ensure topic-list adapter never serializes `undefined` (#17924)

There was existing logic for this, but it was broken because the values were being run through `encodeURI` before checking its type. This commit takes the opportunity to modernise the function to use `URLSearchParams`, which means we no longer need to handle encoding/joining strings manually.

Co-authored-by: Jarek Radosz <jradosz@gmail.com>
This commit is contained in:
David Taylor 2022-08-15 12:16:01 +01:00 committed by GitHub
parent 6e5f08543e
commit 3d070b4a32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 8 deletions

View File

@ -8,18 +8,18 @@ export function finderFor(filter, params) {
let url = getURL("/") + filter + ".json"; let url = getURL("/") + filter + ".json";
if (params) { if (params) {
const keys = Object.keys(params), const urlSearchParams = new URLSearchParams();
encoded = [];
keys.forEach(function (p) { for (const [key, value] of Object.entries(params)) {
const value = encodeURI(params[p]);
if (typeof value !== "undefined") { if (typeof value !== "undefined") {
encoded.push(p + "=" + value); urlSearchParams.set(key, value);
}
} }
});
if (encoded.length > 0) { const queryString = urlSearchParams.toString();
url += "?" + encoded.join("&");
if (queryString) {
url += `?${queryString}`;
} }
} }
return ajax(url); return ajax(url);