Skip to content
This repository was archived by the owner on Dec 31, 2024. It is now read-only.

Allowing paths to be null for lookups. #1145

Merged
merged 1 commit into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
})
})