File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed
src/Bridge/Doctrine/Orm/Extension Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -32,3 +32,10 @@ Feature: JSON API pagination handling
32
32
And the JSON node "meta.totalItems" should be equal to the number 10
33
33
And the JSON node "meta.itemsPerPage" should be equal to the number 15
34
34
And the JSON node "meta.currentPage" should be equal to the number 1
35
+
36
+ Scenario : Get a paginated collection with an non numeric page request attribute
37
+ When I send a "GET" request to "/dummies?page[page]=dummie_non_numeric"
38
+ Then the response should be in JSON
39
+ And the response status code should be 400
40
+ And the JSON node title should be equal to 'An error occurred'
41
+ And the JSON node description should be equal to 'Page request attribute must be a numeric value'
Original file line number Diff line number Diff line change 25
25
use Doctrine \ORM \Tools \Pagination \Paginator as DoctrineOrmPaginator ;
26
26
use Symfony \Component \HttpFoundation \Request ;
27
27
use Symfony \Component \HttpFoundation \RequestStack ;
28
+ use Symfony \Component \HttpKernel \Exception \BadRequestHttpException ;
28
29
29
30
/**
30
31
* Applies pagination on the Doctrine query for resource collection when enabled.
@@ -262,6 +263,10 @@ private function useOutputWalkers(QueryBuilder $queryBuilder): bool
262
263
private function getPaginationParameter (Request $ request , string $ parameterName , $ default = null )
263
264
{
264
265
if (null !== $ paginationAttribute = $ request ->attributes ->get ('_api_pagination ' )) {
266
+ if (isset ($ paginationAttribute ['page ' ]) && !is_numeric ($ paginationAttribute ['page ' ])) {
267
+ throw new BadRequestHttpException ('Page request attribute must be a numeric value ' );
268
+ }
269
+
265
270
return array_key_exists ($ parameterName , $ paginationAttribute ) ? $ paginationAttribute [$ parameterName ] : $ default ;
266
271
}
267
272
You can’t perform that action at this time.
0 commit comments