API Platform version(s) affected: 2.6.0+
Description
Hi, after upgrading v2.5.7 -> v2.6.4 I am facing the strange behaviour with required filter parameter on nested property. QueryParameterValidator.php (line 65) then returns FilterValidationException: Query parameter "x.y" is required even it is present in query and can work.
Once the filter is set to be required i.e. in a custom filter, the Filter\Validator\Require class fails to test requestHasQueryParameter() when the parameter name contains dot (used for nested properties). This looks to be introduced in #1723, where new Require class compares $queryParameters array in form "x.y" with result of parse_str() which converts dots to "x_y" (see e.g. https://stackoverflow.com/questions/68651/get-php-to-stop-replacing-characters-in-get-or-post-arrays) - this cannot match, then an exception is thrown.
How to reproduce
- Set custom filter class with
'required' => false
Filter\Validator\Require test passes and filter works(!)
Possible Solution
Some workaround for parse_str() like here https://stackoverflow.com/questions/22539633/parse-string-containing-dots-in-php ?
Or compare output of parse_str() with $request->query->all() which also has underscores instead of dots, as it is in v2.5.7 (https://github.com/api-platform/core/blob/37b5edf50cc05299b12cb8982be3efa035d726ce/src/Filter/QueryParameterValidateListener.php)
Or get underscores also in $queryParameters?
Additional Context
Require class https://github.com/api-platform/core/pull/1723/files#diff-900c533383b3b17876e6a5c81e525632c8a492358f36f352b0db974e4d604a09
Test simple code
<?php
parse_str("x.y", $blabla);
var_dump($blabla);
which outputs
array(1) {
["x_y"]=>
string(0) ""
}
API Platform version(s) affected: 2.6.0+
Description
Hi, after upgrading v2.5.7 -> v2.6.4 I am facing the strange behaviour with required filter parameter on nested property.
QueryParameterValidator.php(line 65) then returnsFilterValidationException: Query parameter "x.y" is requiredeven it is present in query and can work.Once the filter is set to be required i.e. in a custom filter, the
Filter\Validator\Requireclass fails to testrequestHasQueryParameter()when the parameter name contains dot (used for nested properties). This looks to be introduced in #1723, where newRequireclass compares$queryParametersarray in form "x.y" with result ofparse_str()which converts dots to "x_y" (see e.g. https://stackoverflow.com/questions/68651/get-php-to-stop-replacing-characters-in-get-or-post-arrays) - this cannot match, then an exception is thrown.How to reproduce
getDescription()method with'required' => truelike here https://api-platform.com/docs/core/filters/#creating-custom-filtersFilter\Validator\Requirecomplains on missing parameter?!'required' => falseFilter\Validator\Requiretest passes and filter works(!)Possible Solution
Some workaround for
parse_str()like here https://stackoverflow.com/questions/22539633/parse-string-containing-dots-in-php ?Or compare output of
parse_str()with$request->query->all()which also has underscores instead of dots, as it is in v2.5.7 (https://github.com/api-platform/core/blob/37b5edf50cc05299b12cb8982be3efa035d726ce/src/Filter/QueryParameterValidateListener.php)Or get underscores also in
$queryParameters?Additional Context
Requireclass https://github.com/api-platform/core/pull/1723/files#diff-900c533383b3b17876e6a5c81e525632c8a492358f36f352b0db974e4d604a09Test simple code
which outputs