Be more liberal in what chars a variable can contain
May break some undocumented cases… cf #139 #676
This commit is contained in:
parent
a0654776f6
commit
95e1745e6f
2 changed files with 20 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue