From 5d26ef8af2e16ab5fa15c01a76e1fa4bbdd1786d Mon Sep 17 00:00:00 2001 From: Nikaple Date: Fri, 3 Nov 2023 17:20:28 +0800 Subject: [PATCH] fix: keys ends with dot --- src/internal.test.ts | 1 + src/internal.ts | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/internal.test.ts b/src/internal.test.ts index 0973cbe..e302da9 100644 --- a/src/internal.test.ts +++ b/src/internal.test.ts @@ -69,6 +69,7 @@ describe('parsePath', () => { expect(() => strictParse('foo.bar".qux')).toThrowError(); expect(() => strictParse('a - b')).toThrowError(); expect(() => strictParse('a.1')).toThrowError(); + expect(() => strictParse('a.')).toThrowError(); expect(() => strictParse('a.cb[]]')).toThrowError(); expect(() => strictParse('a["a]')).toThrowError(); expect(() => strictParse('a["a\\"]')).toThrowError(); diff --git a/src/internal.ts b/src/internal.ts index f922835..7f62e5c 100644 --- a/src/internal.ts +++ b/src/internal.ts @@ -30,7 +30,11 @@ export const parsePath = (str: string, strict = false): (string | number)[] => { const char = str[i]; if (char === '.') { i++; - if (SPECIAL_CHARACTER_REGEX.test(str[i]) || /[0-9]/.test(str[i])) { + if ( + SPECIAL_CHARACTER_REGEX.test(str[i]) || + /[0-9]/.test(str[i]) || + !str[i] + ) { panic(i); } continue;