From bdabdad5916a7960299aede01c87ad3e1f27716a Mon Sep 17 00:00:00 2001 From: Marite Guerrieri Date: Tue, 17 Oct 2023 17:21:37 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20work=20around=20on=20yaml=20libr?= =?UTF-8?q?ary=20problems?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Due to a bug in js-yaml, non-octal 0 padded numeric codes are parsed as number instead strings and we are losing the code zero padding. https://github.com/nodeca/js-yaml/issues/684 Co-authored-by: David García Garzón --- src/services/utils.js | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/services/utils.js b/src/services/utils.js index e00c1e8..742122e 100644 --- a/src/services/utils.js +++ b/src/services/utils.js @@ -35,15 +35,35 @@ export const loadAllLocations = async (geoLevels) => { } return requestOpenApi(uriBase + `/discover/geolevel/${geolevel.id}`).then( (yamldata) => { + /* + Work around on yaml library problems + + Due to a bug in js-yaml, non-octal 0 padded numeric codes + are parsed as number instead strings and we are losing + the code zero padding. + + https://github.com/nodeca/js-yaml/issues/684 + */ + function paddingHack(geolevel, id) { + const padding = { + ccaa: 2, + state: 2, + city: 5, + } + const geolevelPadding = padding[geolevel] + if (geolevelPadding === undefined) return id; + return (id+"").padStart(geolevelPadding, '0') + } const data = yaml.load(yamldata) for (const [id, text] of Object.entries(data.options)) { + const paddedId = paddingHack(geolevel.id, id) allLocations.push({ - id, + id: paddedId, text, level: geolevel, filterText: `${text} (${geolevel.text})`, - filterQuery: `${geolevel.id}=${id}`, - key: id + filterQuery: `${geolevel.id}=${paddedId}`, + key: paddedId, }) } }