Repository navigation
fix: accept sparse numeric keys in search filters - #8863
Conversation
| // associative arrays are operator-maps owned by ComparisonFilter/DateFilter, not equality | ||
| if (\is_array($values) && !array_is_list($values)) { | ||
| return; | ||
| // String keys denote operators owned by filters such as ComparisonFilter and DateFilter. |
There was a problem hiding this comment.
could we clean with array_values($values) to transform it as a list everytime ?
Also, this fix should be done in ExactFilter too
There was a problem hiding this comment.
We can use array_values() after checking the original keys, but not unconditionally. array_values(['lt' => 'beta']) produces ['beta'], so the search filter would also run on input meant for ComparisonFilter. PartialSearchFilter already reindexes when it collects scalar values.
I’ve added the same fix to ORM ExactFilter, where we explicitly reindex after checking the keys. The HTTP regression test passes, and the existing [lt] test still passes.
There was a problem hiding this comment.
Yes, both ODM filters have the same guard. I’ll apply the same rule to ODM ExactFilter and PartialSearchFilter: accept sparse integer keys, but leave string-keyed operator maps alone. I’ll add MongoDB-backed regression coverage for both.
|
Hi @soyuka, could you review this PR when you have a chance? Thanks! |
68eac40 to
26644f4
Compare
|
Thanks! |
What
Doctrine ORM's
ExactFilterandPartialSearchFilterignored arrays with non-contiguous integer keys. Those keys are valid multi-value input, not operator names. Both filters now accept them while still leaving string-keyed operator maps to filters such asComparisonFilterandDateFilter.flowchart LR A["Bookstore app needs books alpha, beta, gamma"] --> B["beta is already in its local catalog"] B --> C["array_diff removes beta but preserves keys 0 and 2"] C --> D["GET /books?code[0]=alpha&code[2]=gamma"] D --> E["Before: filter ignored; returns alpha, beta, gamma"] D --> F["After: filter applied; returns only alpha and gamma"]Tests
HTTP regression tests seed
alpha,beta, andgammaand assert that both ordinary lists and sparse indices return onlyalphaandbeta. The existing test combiningExactFilterandComparisonFilterstill verifies that[lt]applies only the comparison.Targeted local run: 82 passed, 8 skipped, 311 assertions. PHP CS Fixer reported no changes.