mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
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:
parent
157e243eee
commit
15a423ad70
2 changed files with 16 additions and 0 deletions
|
@ -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,
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue