Permalink
Browse files

Restrict page number passed to view.

Limit the page number to the max page number when passing data to the
view.  This prevents the helper from generating a huge number of links.

Fixes #2929
  • Loading branch information...
1 parent 157e243 commit 15a423ad70709c087acaedee44f1d17c33896244 @markstory markstory committed Jun 3, 2012
View
1 lib/Cake/Controller/Component/PaginatorComponent.php
@@ -184,6 +184,7 @@ public function paginate($object = null, $scope = array(), $whitelist = array())
$count = $object->find('count', array_merge($parameters, $extra));
}
$pageCount = intval(ceil($count / $limit));
+ $page = min($page, $pageCount);
$paging = array(
'page' => $page,
View
15 lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php
@@ -714,6 +714,21 @@ public function testValidateSortInvalidDirection() {
}
/**
+ * Test that a really large page number gets clamped to the max page size.
+ */
+ public function testOutOfRangePageNumberGetsClamped() {
+ $Controller = new PaginatorTestController($this->request);
+ $Controller->uses = array('PaginatorControllerPost');
+ $Controller->params['named'] = array(
+ 'page' => 3000,
+ );
+ $Controller->constructClasses();
+ $Controller->PaginatorControllerPost->recursive = 0;
+ $Controller->Paginator->paginate('PaginatorControllerPost');
+ $this->assertEquals(1, $Controller->request->params['paging']['PaginatorControllerPost']['page']);
+ }
+
+/**
* test that fields not in whitelist won't be part of order conditions.
*
* @return void

0 comments on commit 15a423a

Please sign in to comment.