Skip to content

Commit

Permalink
Restrict page number passed to view.
Browse files Browse the repository at this point in the history
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 15a423a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/Cake/Controller/Component/PaginatorComponent.php
Expand Up @@ -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,
Expand Down
15 changes: 15 additions & 0 deletions lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php
Expand Up @@ -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.
*
Expand Down

0 comments on commit 15a423a

Please sign in to comment.