Skip to content

fix: do not treat empty arrays as universal match#14

Merged
ruoka merged 2 commits into
masterfrom
cursor/critical-bug-management-fd9d
Jul 20, 2026
Merged

fix: do not treat empty arrays as universal match#14
ruoka merged 2 commits into
masterfrom
cursor/critical-bug-management-fd9d

Conversation

@cursor

@cursor cursor Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

object::match treated any empty subset as a universal match via subset.empty(). Empty arrays are empty too, so:

  • {"$in":[[]]} matched any primitive value
  • {"$nin":[[]]} matched no values
  • field selectors like {"tags":[]} matched any tags value

Query filters could silently match all (or none) of the intended documents.

Root cause

The early return if (subset.empty()) return true is correct for Mongo-style empty object queries ({}), but array matching is same-length equality and $in/$nin reuse match() 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

  • Updated MatchArray and added $in/$nin/field-equality regressions in MatchInNinAcceptArrayOperand.
  • ./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.

Open in Web View Automation 

cursoragent and others added 2 commits July 20, 2026 18:43
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
ruoka marked this pull request as ready for review July 20, 2026 21:31
@ruoka
ruoka merged commit 328b8bc into master Jul 20, 2026
4 checks passed
@ruoka
ruoka deleted the cursor/critical-bug-management-fd9d branch 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants