Merge pull request #1221 from umap-project/non-ascii-variables

Be more liberal in what chars a variable can contain
This commit is contained in:
Yohan Boniface 2023-07-22 09:10:12 +02:00 committed by GitHub
commit 5261daf6ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View file

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

View file

@ -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(