Return first defined property instead of last property

The changes done in b29adaa5 and ec275d64 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:
Manfred Stock 2020-12-12 17:47:41 +01:00
parent 7893ff1c7d
commit 77d9e1f4e2
2 changed files with 8 additions and 0 deletions

View file

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

View file

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