From 928b87862298e32850255307884be86b06351c0c Mon Sep 17 00:00:00 2001 From: Martin Heidegger Date: Thu, 11 Mar 2021 17:16:12 +0900 Subject: [PATCH] Allowing paths to be null for lookups. --- src/path.js | 2 +- test/unit/path.test.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/path.js b/src/path.js index 4b50fd7e6..6afeeb8b0 100644 --- a/src/path.js +++ b/src/path.js @@ -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 diff --git a/test/unit/path.test.js b/test/unit/path.test.js index 566b45f03..23292d6f6 100644 --- a/test/unit/path.test.js +++ b/test/unit/path.test.js @@ -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) + }) + }) })