Return first defined property instead of last property
The changes done inb29adaa5
andec275d64
introduced a property fallback, however, this always returned the property/string in the rightmost position, ignoring any of the previous values, even if they were defined.
This commit is contained in:
parent
7893ff1c7d
commit
77d9e1f4e2
2 changed files with 8 additions and 0 deletions
|
@ -140,6 +140,7 @@ L.Util.greedyTemplate = function (str, data, ignore) {
|
|||
path = vars[i];
|
||||
if (path.startsWith('"') && path.endsWith('"')) value = path.substring(1, path.length -1); // static default value.
|
||||
else value = getValue(data, path.split('.'));
|
||||
if (value !== undefined) break;
|
||||
}
|
||||
if (value === undefined) {
|
||||
if (ignore) value = str;
|
||||
|
|
|
@ -178,6 +178,13 @@ describe('L.Util', function () {
|
|||
assert.equal(L.Util.greedyTemplate('A phrase with a {fr.var.bar|try.again|"default"}.', {}), 'A phrase with a default.');
|
||||
});
|
||||
|
||||
it('should use the first defined value', function () {
|
||||
assert.equal(L.Util.greedyTemplate('A phrase with a {fr.var.bar|try.again|"default"}.', {try: { again: 'please'}}), 'A phrase with a please.');
|
||||
});
|
||||
|
||||
it('should use the first defined value', function () {
|
||||
assert.equal(L.Util.greedyTemplate('A phrase with a {fr.var.bar|try.again|"default"}.', {try: { again: 'again'}, fr: {var: {bar: 'value'}}}), 'A phrase with a value.');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#TextColorFromBackgroundColor', function () {
|
||||
|
|
Loading…
Reference in a new issue