Skip to content

Commit 677f923

Browse files
vladimirDaronsoyuka
authored andcommitted
Fix bug Pagination throws 500 when etrying set large value page
1 parent 3716126 commit 677f923

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

features/jsonapi/pagination.feature

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ Feature: JSON API pagination handling
3636
Scenario: Get an error when provided page number is not valid
3737
When I send a "GET" request to "/dummies?page[page]=0"
3838
Then the response status code should be 400
39+
40+
Scenario: Get an error when provided page number is too large
41+
When I send a "GET" request to "/dummies?page[page]=9223372036854775807"
42+
Then the response status code should be 400

src/DataProvider/Pagination.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,14 @@ public function getOffset(string $resourceClass = null, string $operationName =
9090
if ($graphql && null !== ($last = $this->getParameterFromContext($context, 'last'))) {
9191
return ($offset = ($context['count'] ?? 0) - $last) < 0 ? 0 : $offset;
9292
}
93+
94+
$offset = ($this->getPage($context) - 1) * $limit;
95+
96+
if (!\is_int($offset)) {
97+
throw new InvalidArgumentException('Page parameter is too large.');
98+
}
9399

94-
return ($this->getPage($context) - 1) * $limit;
100+
return $offset;
95101
}
96102

97103
/**

0 commit comments

Comments
 (0)