Skip to content
Permalink
Browse files

Allow empty sortWhitelist to not allow sorting at all.

  • Loading branch information...
dereuromark committed Jun 19, 2015
1 parent 5f561f1 commit d538435163f02b7318efa7bc69e68ff91d204e27
@@ -115,6 +115,8 @@ public function implementedEvents()
* ];
* ```
*
* Passing an empty array as whitelist disallows sorting altogether.
*
* ### Paginating with custom finders
*
* You can paginate with any find type defined on your table using the `finder` option.
@@ -319,7 +321,7 @@ public function validateSort(Table $object, array $options)
}
$inWhitelist = false;
if (!empty($options['sortWhitelist'])) {
if (isset($options['sortWhitelist'])) {
$field = key($options['order']);
$inWhitelist = in_array($field, $options['sortWhitelist'], true);
if (!$inWhitelist) {
@@ -574,6 +574,34 @@ public function testValidateSortWhitelistTrusted()
);
}
/**
* test that whitelist as empty array does not allow any sorting
*
* @return void
*/
public function testValidateSortWhitelistEmpty()
{
$model = $this->getMock('Cake\ORM\Table');
$model->expects($this->any())
->method('alias')
->will($this->returnValue('model'));
$model->expects($this->any())->method('hasField')
->will($this->returnValue(true));
$options = [
'order' => [
'body' => 'asc',
'foo.bar' => 'asc'
],
'sort' => 'body',
'direction' => 'asc',
'sortWhitelist' => []
];
$result = $this->Paginator->validateSort($model, $options);
$this->assertSame([], $result['order'], 'No sort should be applied');
}
/**
* test that fields in the whitelist are not validated
*

0 comments on commit d538435

Please sign in to comment.
You can’t perform that action at this time.