From 647d8910c0a1251eae558cbb5bbfa2a63bc50e53 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Mon, 18 Sep 2023 12:19:52 +0200 Subject: [PATCH] Remove dot in property name Otherwise it will break when trying to access it in FormBuilder --- umap/static/umap/js/umap.features.js | 14 +++++++++++--- umap/static/umap/test/Map.js | 12 ++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/umap/static/umap/js/umap.features.js b/umap/static/umap/js/umap.features.js index 997218ff..40ec7927 100644 --- a/umap/static/umap/js/umap.features.js +++ b/umap/static/umap/js/umap.features.js @@ -193,8 +193,7 @@ L.U.FeatureMixin = { if (fallback === undefined) fallback = this.datalayer.options.name const key = this.getOption('labelKey') || 'name' // Variables mode. - if (L.Util.hasVar(key)) - return L.Util.greedyTemplate(key, this.extendedProperties()) + if (L.Util.hasVar(key)) return L.Util.greedyTemplate(key, this.extendedProperties()) // Simple mode. return this.properties[key] || this.properties.title || fallback }, @@ -244,8 +243,17 @@ L.U.FeatureMixin = { } }, + cleanProperty: function ([key, value]) { + // dot in key will break the dot based property access + // while editing the feature + key = key.replace('.', '_') + return [key, value] + }, + populate: function (feature) { - this.properties = L.extend({}, feature.properties) + this.properties = Object.fromEntries( + Object.entries(feature.properties || {}).map(this.cleanProperty) + ) this.properties._umap_options = L.extend( {}, this.properties._storage_options, diff --git a/umap/static/umap/test/Map.js b/umap/static/umap/test/Map.js index a7146926..c6a9eb15 100644 --- a/umap/static/umap/test/Map.js +++ b/umap/static/umap/test/Map.js @@ -148,6 +148,18 @@ describe('L.U.Map', function () { assert.equal(this.datalayer._index.length, 2) }) + it('should remove dot in property name', function () { + this.datalayer.empty() + assert.equal(this.datalayer._index.length, 0) + textarea.value = + '{"type": "FeatureCollection", "features": [{"geometry": {"type": "Point", "coordinates": [6.922931671142578, 47.481161607175736]}, "type": "Feature", "properties": {"color": "", "name": "Chez R\u00e9my", "A . in the name": ""}}, {"geometry": {"type": "LineString", "coordinates": [[2.4609375, 48.88639177703194], [2.48291015625, 48.76343113791796], [2.164306640625, 48.719961222646276]]}, "type": "Feature", "properties": {"color": "", "name": "P\u00e9rif", "with a dot.": ""}}]}' + changeSelectValue(formatSelect, 'geojson') + happen.click(submit) + assert.equal(this.datalayer._index.length, 2) + assert.ok(this.datalayer._propertiesIndex.includes('A _ in the name')) + assert.ok(this.datalayer._propertiesIndex.includes('with a dot_')) + }) + it('should import osm from textarea', function () { this.datalayer.empty() happen.click(qs('a.upload-data'))