Skip to content
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

Fix error pagination #3451

Merged
merged 2 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions features/jsonapi/pagination.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ Feature: JSON API pagination handling
Scenario: Get an error when provided page number is not valid
When I send a "GET" request to "/dummies?page[page]=0"
Then the response status code should be 400

Scenario: Get an error when provided page number is too large
When I send a "GET" request to "/dummies?page[page]=9223372036854775807"
Then the response status code should be 400
8 changes: 7 additions & 1 deletion src/DataProvider/Pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,13 @@ public function getOffset(string $resourceClass = null, string $operationName =
return ($offset = ($context['count'] ?? 0) - $last) < 0 ? 0 : $offset;
}

return ($this->getPage($context) - 1) * $limit;
$offset = ($this->getPage($context) - 1) * $limit;

if (!\is_int($offset)) {
throw new InvalidArgumentException('Page parameter is too large.');
}

return $offset;
}

/**
Expand Down