-
Notifications
You must be signed in to change notification settings - Fork 556
fix(isDeepKey): improve deep key detection to match strict patterns #1621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
04274f0
da895cc
6bec8ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,15 +14,30 @@ | |||||||||||||||
| * isDeepKey(123) // false | ||||||||||||||||
| * isDeepKey('a.b.c') // true | ||||||||||||||||
| * isDeepKey('a[b][c]') // true | ||||||||||||||||
| * isDeepKey('a.') // false | ||||||||||||||||
| * isDeepKey('.a') // false | ||||||||||||||||
| * isDeepKey('a[b') // false | ||||||||||||||||
| * isDeepKey('a]b]') // false | ||||||||||||||||
| * isDeepKey('a][b') // false | ||||||||||||||||
| */ | ||||||||||||||||
| export function isDeepKey(key: PropertyKey): boolean { | ||||||||||||||||
| switch (typeof key) { | ||||||||||||||||
| case 'number': | ||||||||||||||||
| case 'symbol': { | ||||||||||||||||
| return false; | ||||||||||||||||
| if (typeof key === 'number' || typeof key === 'symbol') { | ||||||||||||||||
| return false; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| if (typeof key === 'string') { | ||||||||||||||||
| const dotIndex = key.indexOf('.'); | ||||||||||||||||
| if (dotIndex > 0 && dotIndex < key.length - 1) { | ||||||||||||||||
| return true; | ||||||||||||||||
|
||||||||||||||||
| if (dotIndex > 0 && dotIndex < key.length - 1) { | |
| return true; | |
| if (dotIndex !== -1) { | |
| const segments = key.split('.'); | |
| if (segments.length > 1 && segments.every(segment => segment.length > 0)) { | |
| return true; | |
| } |
Copilot
AI
Feb 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bracket check only verifies that the first '[' appears before the first ']'. It will still return true for invalid/mismatched bracket patterns like a[b][c (unclosed), a[b]] (extra ']'), a.b[ (unclosed), or a[b]c (missing separator). To meet the strict-pattern intent, this likely needs a small parser/regex that validates balanced bracket segments and disallows stray brackets outside of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The updated tests cover a handful of invalid patterns, but they don't cover several false positives the new implementation still allows (e.g.
a..b,a.b.,a[b][c,a[b]],a[b]c,a.b[). Adding cases like these would prevent regressions and ensure the “strict pattern” behavior described in the PR.