Browse Source

Merge branch '2.1' into 2.2

mark_story 14 years ago
parent
commit
8da42dfcfa

+ 1 - 1
lib/Cake/Console/ConsoleOutput.php

@@ -186,7 +186,7 @@ class ConsoleOutput {
 			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
 		);
 	}
 

+ 2 - 1
lib/Cake/Controller/Component/PaginatorComponent.php

@@ -185,6 +185,7 @@ class PaginatorComponent extends Component {
 			$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 @@ class PaginatorComponent extends Component {
 		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;
 	}
 

+ 29 - 0
lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php

@@ -805,6 +805,35 @@ class PaginatorComponentTest extends CakeTestCase {
 	}
 
 /**
+ * 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.
  *
  * @return void