mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
parent
3c48552f81
commit
f4c27e04bc
2 changed files with 21 additions and 1 deletions
|
@ -333,7 +333,7 @@ class PaginatorComponent extends Component {
|
|||
$options['order'] = array($options['sort'] => $direction);
|
||||
}
|
||||
|
||||
if (!empty($whitelist)) {
|
||||
if (!empty($whitelist) && isset($options['order']) && is_array($options['order'])) {
|
||||
$field = key($options['order']);
|
||||
if (!in_array($field, $whitelist)) {
|
||||
$options['order'] = null;
|
||||
|
|
|
@ -776,6 +776,26 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
$this->assertEquals($expected, $result['order']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that no sort doesn't trigger an error.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testValidateSortNoSort() {
|
||||
$model = $this->getMock('Model');
|
||||
$model->alias = 'model';
|
||||
$model->expects($this->any())->method('hasField')->will($this->returnValue(true));
|
||||
|
||||
$options = array('direction' => 'asc');
|
||||
$result = $this->Paginator->validateSort($model, $options, array('title', 'id'));
|
||||
$this->assertFalse(isset($result['order']));
|
||||
|
||||
$options = array('order' => 'invalid desc');
|
||||
$result = $this->Paginator->validateSort($model, $options, array('title', 'id'));
|
||||
|
||||
$this->assertEquals($options['order'], $result['order']);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that maxLimit is respected
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue