fix: do not treat empty arrays as universal match#14
Merged
Conversation
object::match used subset.empty() for both {} and [], so empty-array
candidates made {"$in":[[]]} match any value and {"tags":[]} match any
tags. Restrict the wildcard to empty objects; arrays keep same-length
equality.
Co-authored-by: Kaius Ruokonen <ruoka@users.noreply.github.com>
$in/$nin only apply on primitive match paths; empty-array LHS never enters that branch. Keep the primitive and field-equality regressions. Co-authored-by: Kaius Ruokonen <ruoka@users.noreply.github.com>
ruoka
marked this pull request as ready for review
July 20, 2026 21:31
ruoka
added a commit
that referenced
this pull request
Jul 21, 2026
* fix: do not treat empty arrays as universal match
object::match used subset.empty() for both {} and [], so empty-array
candidates made {"$in":[[]]} match any value and {"tags":[]} match any
tags. Restrict the wildcard to empty objects; arrays keep same-length
equality.
Co-authored-by: Kaius Ruokonen <ruoka@users.noreply.github.com>
* test: drop invalid $in assertions on array LHS
$in/$nin only apply on primitive match paths; empty-array LHS never
enters that branch. Keep the primitive and field-equality regressions.
Co-authored-by: Kaius Ruokonen <ruoka@users.noreply.github.com>
---------
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Kaius Ruokonen <ruoka@users.noreply.github.com>
This was referenced Jul 21, 2026
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.
Bug and impact
object::matchtreated any empty subset as a universal match viasubset.empty(). Empty arrays are empty too, so:{"$in":[[]]}matched any primitive value{"$nin":[[]]}matched no values{"tags":[]}matched anytagsvalueQuery filters could silently match all (or none) of the intended documents.
Root cause
The early return
if (subset.empty()) return trueis correct for Mongo-style empty object queries ({}), but array matching is same-length equality and$in/$ninreusematch()for candidates. Empty arrays must not share the object wildcard.Fix
Restrict the wildcard to empty objects:
subset.has_objects() && subset.empty(). Empty arrays fall through to the existing array equality path (or mismatch → false).Validation
MatchArrayand added$in/$nin/field-equality regressions inMatchInNinAcceptArrayOperand../tools/CB.sh debug test --tags='\[xson\]'— 410/410 passed.Also noted
PR #13 (FSON object name/value pairing) remains open and is a separate issue.