From 95e1745e6f86387f14e4baea3634199041ac3cfa Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Thu, 20 Jul 2023 14:14:56 +0200 Subject: [PATCH] Be more liberal in what chars a variable can contain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit May break some undocumented cases… cf #139 #676 --- umap/static/umap/js/umap.core.js | 2 +- umap/static/umap/test/Util.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/umap/static/umap/js/umap.core.js b/umap/static/umap/js/umap.core.js index 0584fd31..fb85a047 100644 --- a/umap/static/umap/js/umap.core.js +++ b/umap/static/umap/js/umap.core.js @@ -174,7 +174,7 @@ L.Util.greedyTemplate = (str, data, ignore) => { } return str.replace( - /\{ *([\w_\:\.\|@]+)(?:\|("[^"]*"))? *\}/g, + /\{ *([^\{\}/\-]+)(?:\|("[^"]*"))? *\}/g, (str, key, staticFallback) => { const vars = key.split('|') let value diff --git a/umap/static/umap/test/Util.js b/umap/static/umap/test/Util.js index 45800e98..57c75b2d 100644 --- a/umap/static/umap/test/Util.js +++ b/umap/static/umap/test/Util.js @@ -245,6 +245,25 @@ describe('L.Util', function () { ) }) + it('should accept space', function () { + assert.equal( + L.Util.greedyTemplate('A phrase with a {var iable}.', { + 'var iable': 'value', + }), + 'A phrase with a value.' + ) + }) + + it('should accept non ascii chars', function () { + assert.equal( + L.Util.greedyTemplate('A phrase with a {Accessibilité} and {переменная}.', { + 'Accessibilité': 'value', + 'переменная': 'another', + }), + 'A phrase with a value and another.' + ) + }) + it('should replace even with ignore if key is found', function () { assert.equal( L.Util.greedyTemplate(