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";
|
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);
|
||||||
|
|
Loading…
Reference in New Issue