mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-10 05:22:41 +00:00
Adding checks to force limit to always be a positive integer. Fixes potential out of bounds type queries with paginate(). Fixes #418
This commit is contained in:
parent
d8a757ce75
commit
4c668c036c
2 changed files with 14 additions and 1 deletions
|
@ -1168,8 +1168,13 @@ class Controller extends Object {
|
|||
$type = $defaults[0];
|
||||
unset($defaults[0]);
|
||||
}
|
||||
|
||||
$options = array_merge(array('page' => 1, 'limit' => 20), $defaults, $options);
|
||||
$options['limit'] = (empty($options['limit']) || !is_numeric($options['limit'])) ? 1 : $options['limit'];
|
||||
$options['limit'] = (int) $options['limit'];
|
||||
if (empty($options['limit']) || $options['limit'] < 1) {
|
||||
$options['limit'] = 1;
|
||||
}
|
||||
|
||||
extract($options);
|
||||
|
||||
if (is_array($scope) && !empty($scope)) {
|
||||
|
|
|
@ -595,6 +595,14 @@ class ControllerTest extends CakeTestCase {
|
|||
$this->assertIdentical($Controller->params['paging']['ControllerPost']['pageCount'], 3);
|
||||
$this->assertIdentical($Controller->params['paging']['ControllerPost']['prevPage'], false);
|
||||
$this->assertIdentical($Controller->params['paging']['ControllerPost']['nextPage'], true);
|
||||
|
||||
$Controller->passedArgs = array();
|
||||
$Controller->paginate = array('limit' => '-1');
|
||||
$Controller->paginate('ControllerPost');
|
||||
$this->assertIdentical($Controller->params['paging']['ControllerPost']['page'], 1);
|
||||
$this->assertIdentical($Controller->params['paging']['ControllerPost']['pageCount'], 3);
|
||||
$this->assertIdentical($Controller->params['paging']['ControllerPost']['prevPage'], false);
|
||||
$this->assertIdentical($Controller->params['paging']['ControllerPost']['nextPage'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue