Merge pull request #8698 from tchak/fix-adresse-select

fix(autocomplete): avoid double escape of query params
This commit is contained in:
Paul Chavard 2023-02-27 11:32:46 +00:00 committed by GitHub
commit b9080e2ff5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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();
};