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:
parent
6e5f08543e
commit
3d070b4a32
|
@ -8,18 +8,18 @@ export function finderFor(filter, params) {
|
|||
let url = getURL("/") + filter + ".json";
|
||||
|
||||
if (params) {
|
||||
const keys = Object.keys(params),
|
||||
encoded = [];
|
||||
const urlSearchParams = new URLSearchParams();
|
||||
|
||||
keys.forEach(function (p) {
|
||||
const value = encodeURI(params[p]);
|
||||
for (const [key, value] of Object.entries(params)) {
|
||||
if (typeof value !== "undefined") {
|
||||
encoded.push(p + "=" + value);
|
||||
urlSearchParams.set(key, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (encoded.length > 0) {
|
||||
url += "?" + encoded.join("&");
|
||||
const queryString = urlSearchParams.toString();
|
||||
|
||||
if (queryString) {
|
||||
url += `?${queryString}`;
|
||||
}
|
||||
}
|
||||
return ajax(url);
|
||||
|
|
Loading…
Reference in New Issue