Skip to content
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...
markstory committed Jun 3, 2012
1 parent 157e243 commit 15a423ad70709c087acaedee44f1d17c33896244
@@ -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,
@@ -713,6 +713,21 @@ public function testValidateSortInvalidDirection() {
$this->assertEquals('asc', $result['order']['model.something']);
}
/**
* 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.
*

0 comments on commit 15a423a

Please sign in to comment.
You can’t perform that action at this time.