-
-
Notifications
You must be signed in to change notification settings - Fork 920
Avoid to call OrderFilter on wrong properties #1663
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
Conversation
@@ -79,6 +79,7 @@ public function __construct(ManagerRegistry $managerRegistry, RequestStack $requ | |||
public function apply(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, string $operationName = null, array $context = []) | |||
{ | |||
if (!isset($context['filters'][$this->orderParameterName]) || !\is_array($context['filters'][$this->orderParameterName])) { | |||
$context['filters'] = null; |
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.
looks hackish no? Any other way we could fix that?
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.
My first though @soyuka was to remove the call to parent::apply() but it was breaking phpunit test suite. The issue to solve here is to call the grand parent function without calling the parent function.
To be more explicit, in this if we would need to call AbstractFilter::apply()
without calling AbstractContextAwareFilter::apply()
, this is the way I found.
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.
Mhh yeah ok I think I got it. LGTM then thanks and nice catch btw!
I've just rebased this (it's a master fix because context['filters'] was introduced there). Merging when status 🍏 |
thanks @antograssiot |
Avoid to call OrderFilter on wrong properties
On 2.2-beta-1 if a order filter and let say a date filter are declared on the same property (
createdAt
), then calling/dummies?createdAt[before]=2018-01-24
will trigger the date filter and cause aType error: strtoupper() expects parameter 1 to be string, array given in vendor/api-platform/core/src/Bridge/Doctrine/Orm/Filter/OrderFilter.php:134