mirror of
https://github.com/umap-project/umap.git
synced 2025-04-29 03:42:37 +02:00
fix: do not consider null as value in greedyTemplate
cf #820#issuecomment-2227821746
This commit is contained in:
parent
da8e206cd0
commit
6b4b6ce53b
2 changed files with 15 additions and 3 deletions
|
@ -242,10 +242,12 @@ export function greedyTemplate(str, data, ignore) {
|
|||
}
|
||||
for (let i = 0; i < vars.length; i++) {
|
||||
path = vars[i]
|
||||
if (path.startsWith('"') && path.endsWith('"'))
|
||||
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
|
||||
} else {
|
||||
value = getValue(data, path.split('.'))
|
||||
}
|
||||
if (value !== undefined && value !== null) break
|
||||
}
|
||||
if (value === undefined) {
|
||||
if (ignore) value = str
|
||||
|
|
|
@ -433,6 +433,16 @@ describe('Utils', () => {
|
|||
'A phrase with [[https://osm.org|link]] as fallback.'
|
||||
)
|
||||
})
|
||||
|
||||
it('should not consider null values', () => {
|
||||
assert.equal(
|
||||
Utils.greedyTemplate('A phrase with a {foo|fallback}.', {
|
||||
foo: null,
|
||||
fallback: 'default',
|
||||
}),
|
||||
'A phrase with a default.'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#flattenCoordinates()', () => {
|
||||
|
|
Loading…
Reference in a new issue