Skip to content

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

Merged
merged 1 commit into from
Jan 29, 2018

Conversation

antograssiot
Copy link
Contributor

@antograssiot antograssiot commented Jan 24, 2018

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

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 a
Type error: strtoupper() expects parameter 1 to be string, array given in vendor/api-platform/core/src/Bridge/Doctrine/Orm/Filter/OrderFilter.php:134

@@ -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;
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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!

@soyuka
Copy link
Member

soyuka commented Jan 29, 2018

I've just rebased this (it's a master fix because context['filters'] was introduced there). Merging when status 🍏

@soyuka soyuka merged commit bc03ebb into api-platform:master Jan 29, 2018
@soyuka
Copy link
Member

soyuka commented Jan 29, 2018

thanks @antograssiot

@antograssiot antograssiot deleted the order-filter branch January 29, 2018 13:31
hoangnd25 pushed a commit to hoangnd25/core that referenced this pull request Feb 23, 2018
Avoid to call OrderFilter on wrong properties
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.

4 participants