From 46da8f99d646be8609690995db64ce22c9dd9a6f Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Thu, 20 Dec 2018 13:34:53 -0500 Subject: [PATCH] Page number validation. --- module/VuFind/src/VuFind/ILS/PaginationHelper.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/module/VuFind/src/VuFind/ILS/PaginationHelper.php b/module/VuFind/src/VuFind/ILS/PaginationHelper.php index 6d2d6ab7888..28bbd2041cd 100644 --- a/module/VuFind/src/VuFind/ILS/PaginationHelper.php +++ b/module/VuFind/src/VuFind/ILS/PaginationHelper.php @@ -124,7 +124,7 @@ class PaginationHelper // Collect ILS call params $ilsParams = ['sort' => $this->validateSort($functionConfig, $sort)]; if ($ilsPaging) { - $ilsParams['page'] = $page; + $ilsParams['page'] = $page >= 1 ? $page : 1; $ilsParams['limit'] = $limit; } $sortList = $this->getSortList($functionConfig, $ilsParams['sort']); @@ -144,6 +144,10 @@ class PaginationHelper public function getPaginator($pageOptions, $count, $records) { $limit = $pageOptions['limit']; + $page = $pageOptions['page']; + if (($page - 1) * $limit >= $count) { + throw new \VuFind\Exception\BadRequest('Page number out of range.'); + } if ($pageOptions['ilsPaging'] && $limit < $count) { $adapter = new \Zend\Paginator\Adapter\NullFill($count); } elseif ($limit > 0 && $limit < $count) { @@ -153,7 +157,7 @@ class PaginationHelper } $paginator = new \Zend\Paginator\Paginator($adapter); $paginator->setItemCountPerPage($limit); - $paginator->setCurrentPageNumber($pageOptions['page']); + $paginator->setCurrentPageNumber($page); return $paginator; } } -- GitLab