diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index 5fe9bc351..6475aab3b 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -913,6 +913,9 @@ class Controller extends Object { } if (isset($options['sort']) && isset($options['direction'])) { + if (!in_array(strtolower($options['direction']), array('asc', 'desc'))) { + $options['direction'] = 'asc'; + } $options['order'] = array($options['sort'] => $options['direction']); } elseif (isset($options['sort'])) { $options['order'] = array($options['sort'] => 'asc'); diff --git a/cake/tests/cases/libs/controller/controller.test.php b/cake/tests/cases/libs/controller/controller.test.php index 9a267eb8a..fea4a48f6 100644 --- a/cake/tests/cases/libs/controller/controller.test.php +++ b/cake/tests/cases/libs/controller/controller.test.php @@ -323,6 +323,11 @@ class ControllerTest extends CakeTestCase { $results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id'); $this->assertEqual($Controller->params['paging']['ControllerPost']['page'], 1); $this->assertEqual($results, array(1, 2, 3)); + + $Controller->passedArgs = array('sort' => 'ControllerPost.author_id', 'direction' => 'allYourBase'); + $results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id'); + $this->assertEqual($Controller->ControllerPost->lastQuery['order'][0], array('ControllerPost.author_id' => 'asc')); + $this->assertEqual($results, array(1, 3, 2)); } /** * testPaginateExtraParams method