fix: nested _where filters fail open when intermediate field is missing#1744
Open
cyphercodes wants to merge 1 commit intotypicode:mainfrom
Open
fix: nested _where filters fail open when intermediate field is missing#1744cyphercodes wants to merge 1 commit intotypicode:mainfrom
cyphercodes wants to merge 1 commit intotypicode:mainfrom
Conversation
Fixes typicode#1731 When using nested object predicates like { title: { nested: { eq: 'zzz' } } }, the filter would incorrectly return all rows if the intermediate field (title) was not an object. This happened because the code would 'continue' instead of returning false when the field was missing or not an object. The fix adds a hasKnownOperatorsAtAnyLevel() helper to detect when a nested object contains known operators at any depth. If it does, and the field is not an object, the filter now correctly returns false. This preserves the existing fail-open behavior for unknown operators while fixing the fail-closed behavior for nested predicates on non-object fields. - Added hasKnownOperatorsAtAnyLevel() helper function - Modified nested object handling to check for operators at any level - Added regression tests for the specific bug cases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1731
Problem
Nested _where object filters currently fail open when the intermediate field does not exist on the target object or is not an object.
For example, with data
{ title: 'a' }:{ title: { eq: 'zzz' } }correctly returns empty (no match){ title: { nested: { eq: 'zzz' } } }incorrectly returns all rows (fail-open bug)Solution
Added
hasKnownOperatorsAtAnyLevel()helper to detect when a nested object contains known operators at any depth. If it does, and the field is not an object, the filter now correctly returns false.This preserves the existing fail-open behavior for unknown operators while fixing the fail-closed behavior for nested predicates on non-object fields.
Changes
hasKnownOperatorsAtAnyLevel()helper function insrc/matches-where.tsTesting
All 130 tests pass, including 3 new regression tests for this specific issue.