fix(autocomplete): avoid double escape of query params

This commit is contained in:
Paul Chavard 2023-02-27 12:01:12 +01:00
parent 67bbacbb05
commit 68fd34a732

View file

@ -26,7 +26,7 @@ type QueryKey = readonly [
];
function buildURL(scope: string, term: string, extra?: string) {
term = encodeURIComponent(term.replace(/\(|\)/g, ''));
term = term.replace(/\(|\)/g, '');
const params = new URLSearchParams();
let path = `${api_geo_url}/${scope}`;
@ -73,6 +73,11 @@ const defaultQueryFn: QueryFunction<unknown, QueryKey> = async ({
return matchSorter(await getPays(signal), term, { keys: ['label'] });
}
// BAN will error with queries less then 3 chars long
if (scope == 'adresse' && term.length < 3) {
return [];
}
const url = buildURL(scope, term, extra);
return httpRequest(url, { csrf: false, signal }).json();
};