From c1033daac1a4485783b138e652c25ff336d26740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20L=C3=A9cluse?= <laurent.lecluse@unicaen.fr> Date: Tue, 16 May 2023 14:59:30 +0200 Subject: [PATCH] =?UTF-8?q?Correction=20de=20bug=20sur=20unicaenVue.url=20?= =?UTF-8?q?en=20cas=20de=20query=20avec=20objets=20r=C3=A9cursifs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/Client/unicaenVue.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/js/Client/unicaenVue.js b/js/Client/unicaenVue.js index ac1debf..9a02b41 100644 --- a/js/Client/unicaenVue.js +++ b/js/Client/unicaenVue.js @@ -23,10 +23,30 @@ const unicaenVue = { } // traitement de la requĂȘte GET - let getArgs = query ? new URLSearchParams(query).toString() : null; + let getArgs = query ? unicaenVue.encodeUrlQueryParam(query) : null; // Construction et retour de l'URL return baseUrl + route + (getArgs ? `?${getArgs}` : ''); + }, + + encodeUrlQueryParam: (query, parentKey) => { + var params = []; + + for (var key in query) { + if (query.hasOwnProperty(key)) { + var value = query[key]; + var encodedKey = parentKey ? parentKey + '[' + encodeURIComponent(key) + ']' : encodeURIComponent(key); + + if (typeof value === 'object' && value !== null) { + params.push(unicaenVue.encodeUrlQueryParam(value, encodedKey)); + } else { + var encodedValue = encodeURIComponent(value); + params.push(encodedKey + '=' + encodedValue); + } + } + } + + return params.join('&'); } }; -- GitLab