Skip to content

Commit

Permalink
Be more liberal in what chars a variable can contain
Browse files Browse the repository at this point in the history
May break some undocumented cases…

cf #139 #676
  • Loading branch information
yohanboniface committed Jul 20, 2023
1 parent a065477 commit 95e1745
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion umap/static/umap/js/umap.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions umap/static/umap/test/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 95e1745

Please sign in to comment.