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
This commit is contained in:
mark_story 2012-06-02 20:26:09 -04:00
parent 157e243eee
commit 15a423ad70
2 changed files with 16 additions and 0 deletions

View file

@ -184,6 +184,7 @@ class PaginatorComponent extends Component {
$count = $object->find('count', array_merge($parameters, $extra));
}
$pageCount = intval(ceil($count / $limit));
$page = min($page, $pageCount);
$paging = array(
'page' => $page,

View file

@ -713,6 +713,21 @@ class PaginatorComponentTest extends CakeTestCase {
$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.
*