Skip to content

Commit

Permalink
fix: keys ends with dot
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikaple committed Nov 3, 2023
1 parent d9c06e0 commit 5d26ef8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/internal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5d26ef8

Please sign in to comment.