Skip to content

Commit

Permalink
Allowing paths to be null for lookups. (#1145)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinheidegger committed Mar 11, 2021
1 parent 4422c1b commit dc3a559
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export default class I18nPath {
let i: number = 0
while (i < length) {
const value: any = last[paths[i]]
if (value === undefined) {
if (value === undefined || value === null) {
return null
}
last = value
Expand Down
6 changes: 6 additions & 0 deletions test/unit/path.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,10 @@ describe('path', () => {
assert.strictEqual(path.getPathValue({}, 'a.b.c[]d'), null)
})
})

describe('obj: null child', () => {
it('should return null if parent is null', () => {
assert.strictEqual(path.getPathValue({ a: null }, 'a.b'), null)
})
})
})

0 comments on commit dc3a559

Please sign in to comment.