feat: Ensure features ids match the requested format

This commit is contained in:
Alexis Métaireau 2024-02-29 11:38:18 +01:00
parent 702713e768
commit b0334a027d
2 changed files with 12 additions and 4 deletions

View file

@ -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)
}

View file

@ -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 () {},