-
Notifications
You must be signed in to change notification settings - Fork 6
Fix filter operators broken across spec and memory driver #867
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
Changes from all commits
ec6a21c
2ae689c
fdb9155
07b0307
41b6831
f661b46
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 |
|---|---|---|
|
|
@@ -103,7 +103,7 @@ function checkCondition(value: any, condition: any): boolean { | |
| const target = condition[op]; | ||
|
|
||
| // Handle undefined values | ||
| if (value === undefined && op !== '$exists' && op !== '$ne') { | ||
| if (value === undefined && op !== '$exists' && op !== '$ne' && op !== '$null') { | ||
| return false; | ||
| } | ||
|
|
||
|
|
@@ -151,12 +151,20 @@ function checkCondition(value: any, condition: any): boolean { | |
| case '$contains': | ||
| if (typeof value !== 'string' || !value.includes(target)) return false; | ||
| break; | ||
| case '$notContains': | ||
| if (typeof value !== 'string' || value.includes(target)) return false; | ||
| break; | ||
| case '$startsWith': | ||
| if (typeof value !== 'string' || !value.startsWith(target)) return false; | ||
| break; | ||
| case '$endsWith': | ||
| if (typeof value !== 'string' || !value.endsWith(target)) return false; | ||
| break; | ||
| case '$null': | ||
| // $null: true → value must be null/undefined; $null: false → value must not be null/undefined | ||
| if (target === true && value != null) return false; | ||
| if (target === false && value == null) return false; | ||
| break; | ||
|
Comment on lines
+163
to
+167
|
||
| case '$regex': | ||
| try { | ||
| const re = new RegExp(target, condition.$options || ''); | ||
|
|
||
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.
In
normalizeFieldOperators, the cases for$contains,$startsWith, and$endsWithall write toresult.$regex. If a filter has more than one of these operators on the same field (e.g.,{ name: { $startsWith: 'A', $endsWith: 'n' } }), the second operator silently overwrites the$regexset by the first. Only the last processed operator's regex pattern is applied, and the earlier constraints are lost. To fix this, each of these operators should be combined into a single regex (e.g., concatenating both^and$anchors into one expression), or this limitation should be documented.