diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index cce7fedfc..145fda8a8 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -952,6 +952,8 @@ class Controller extends Object { if ($page == 'last' || $page >= $pageCount) { $options['page'] = $page = $pageCount; + } elseif (intval($page) < 1) { + $options['page'] = $page = 1; } if (method_exists($object, 'paginate')) { diff --git a/cake/tests/cases/libs/controller/controller.test.php b/cake/tests/cases/libs/controller/controller.test.php index 9997f88ef..8ef1d1c9c 100644 --- a/cake/tests/cases/libs/controller/controller.test.php +++ b/cake/tests/cases/libs/controller/controller.test.php @@ -96,6 +96,11 @@ class ControllerTest extends CakeTestCase { $Controller->uses[0] = 'Plugin.ControllerPost'; $results = Set::extract($Controller->paginate(), '{n}.ControllerPost.id'); $this->assertEqual($results, array(1, 2, 3)); + + $Controller->passedArgs = array('page' => '-1'); + $results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id'); + $this->assertEqual($Controller->params['paging']['ControllerPost']['page'], 1); + $this->assertEqual($results, array(1, 2, 3)); } }