Skip to content

Commit

Permalink
Fix issue in Required filter validator with dot notation (#4221)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeniau authored Apr 16, 2021
1 parent 14bd387 commit 8d4891a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 2.6.5

* Filter validation: Fix issue in Required filter validator with dot notation (#4221)
* OpenAPI: Fix notice/warning for `response` without `content` in the `openapi_context` (#4210)
* Serializer: Convert internal error to HTTP 400 in Ramsey uuid denormalization from invalid body string (#4200)

Expand Down
8 changes: 4 additions & 4 deletions src/Filter/Validator/Required.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace ApiPlatform\Core\Filter\Validator;

use ApiPlatform\Core\Util\RequestParser;

final class Required implements ValidatorInterface
{
/**
Expand Down Expand Up @@ -47,8 +49,7 @@ public function validate(string $name, array $filterDescription, array $queryPar
*/
private function requestHasQueryParameter(array $queryParameters, string $name): bool
{
$matches = [];
parse_str($name, $matches);
$matches = RequestParser::parseRequestParams($name);
if (!$matches) {
return false;
}
Expand Down Expand Up @@ -76,8 +77,7 @@ private function requestHasQueryParameter(array $queryParameters, string $name):
*/
private function requestGetQueryParameter(array $queryParameters, string $name)
{
$matches = [];
parse_str($name, $matches);
$matches = RequestParser::parseRequestParams($name);
if (empty($matches)) {
return null;
}
Expand Down
29 changes: 29 additions & 0 deletions tests/Filter/Validator/RequiredTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,33 @@ public function testEmptyValueAllowed()
$filter->validate('some_filter', $explicitFilterDefinition, $request)
);
}

public function testBracketNotation()
{
$filter = new Required();

$request = ['foo' => ['bar' => ['bar']]];

$requiredFilter = [
'required' => true,
];

$this->assertEmpty(
$filter->validate('foo[bar]', $requiredFilter, $request)
);
}

public function testDotNotation()
{
$request = ['foo.bar' => 'bar'];
$filter = new Required();

$requiredFilter = [
'required' => true,
];

$this->assertEmpty(
$filter->validate('foo.bar', $requiredFilter, $request)
);
}
}

0 comments on commit 8d4891a

Please sign in to comment.