Permalink
Browse files

Merge branch '2.1' into 2.2

  • Loading branch information...
2 parents 4c64535 + d1819dc commit 8da42dfcfad916247f4afdb27723a9a5962ed355 @markstory markstory committed Jun 3, 2012
@@ -186,7 +186,7 @@ public function styleText($text) {
return preg_replace('#</?(?:' . $tags . ')>#', '', $text);
}
return preg_replace_callback(
- '/<(?<tag>[a-z0-9-_]+)>(?<text>.*?)<\/(\1)>/ims', array($this, '_replaceTags'), $text
+ '/<(?P<tag>[a-z0-9-_]+)>(?P<text>.*?)<\/(\1)>/ims', array($this, '_replaceTags'), $text
);
}
@@ -185,6 +185,7 @@ public function paginate($object = null, $scope = array(), $whitelist = array())
$count = $object->find('count', array_merge($parameters, $extra));
}
$pageCount = intval(ceil($count / $limit));
+ $page = max(min($page, $pageCount), 1);
$paging = array(
'page' => $page,
@@ -375,7 +376,7 @@ public function checkLimit($options) {
if (empty($options['limit']) || $options['limit'] < 1) {
$options['limit'] = 1;
}
- $options['limit'] = min((int)$options['limit'], $options['maxLimit']);
+ $options['limit'] = min($options['limit'], $options['maxLimit']);
return $options;
}
@@ -804,6 +804,35 @@ public function testValidateSortInvalidDirection() {
$this->assertEquals('asc', $result['order']['model.something']);
}
+/**
+ * Test that a really large page number gets clamped to the max page size.
+ */
+ public function testOutOfRangePageNumberGetsClamped() {
+ $Controller = new PaginatorTestController($this->request);
+ $Controller->uses = array('PaginatorControllerPost');
+ $Controller->params['named'] = array(
+ 'page' => 3000,
+ );
+ $Controller->constructClasses();
+ $Controller->PaginatorControllerPost->recursive = 0;
+ $Controller->Paginator->paginate('PaginatorControllerPost');
+ $this->assertEquals(
+ 1,
+ $Controller->request->params['paging']['PaginatorControllerPost']['page'],
+ 'Super big page number should be capped to max number of pages'
+ );
+
+ $Controller->paginate = array(
+ 'conditions' => array('PaginatorControllerPost.id >' => 100)
+ );
+ $Controller->Paginator->paginate('PaginatorControllerPost');
+ $this->assertEquals(
+ 1,
+ $Controller->request->params['paging']['PaginatorControllerPost']['page'],
+ 'Page number should not be 0'
+ );
+ }
+
/**
* test that fields not in whitelist won't be part of order conditions.
*

0 comments on commit 8da42df

Please sign in to comment.