From b0334a027db069d1473e6b69ea101fabc10d9190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Thu, 29 Feb 2024 11:38:18 +0100 Subject: [PATCH] feat: Ensure features ids match the requested format --- umap/static/umap/js/modules/utils.js | 11 +++++++++++ umap/static/umap/js/umap.features.js | 5 +---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/umap/static/umap/js/modules/utils.js b/umap/static/umap/js/modules/utils.js index aa681602..a5116616 100644 --- a/umap/static/umap/js/modules/utils.js +++ b/umap/static/umap/js/modules/utils.js @@ -11,3 +11,14 @@ export function generateId() { return btoa(Math.random().toString()).substring(10, 15) } + +/** + * Ensure the ID matches the expected format. + * + * @param {string} string + * @returns {boolean} + */ +export function checkId(string) { + if (typeof string !== 'string') return false + return /^[A-Za-z0-9]{5}$/.test(string) +} diff --git a/umap/static/umap/js/umap.features.js b/umap/static/umap/js/umap.features.js index 3baacc53..57caecce 100644 --- a/umap/static/umap/js/umap.features.js +++ b/umap/static/umap/js/umap.features.js @@ -16,7 +16,7 @@ U.FeatureMixin = { } // Each feature needs an unique identifier - if (this._checkId(geojson_id)) { + if (U.Utils.checkId(geojson_id)) { this.id = geojson_id } else { this.id = U.Utils.generateId() @@ -45,9 +45,6 @@ U.FeatureMixin = { this.addInteractions() this.parentClass.prototype.initialize.call(this, latlng, options) }, - _checkId: function (string) { - return typeof string !== 'undefined' - }, preInit: function () {},