Browse Source

Merge branch '2.6' into 2.7

mark_story 11 years ago
parent
commit
1c913d29b6

+ 4 - 0
app/Config/database.php.default

@@ -50,6 +50,10 @@
  * For MySQL, Postgres specifies the character encoding to use when connecting to the
  * database. Uses database default not specified.
  *
+ * sslmode =>
+ * For Postgres specifies whether to 'disable', 'allow', 'prefer', or 'require' SSL for the 
+ * connection. The default value is 'allow'.
+ *
  * unix_socket =>
  * For MySQL to connect via socket specify the `unix_socket` parameter instead of `host` and `port`
  *

+ 5 - 1
lib/Cake/Cache/Engine/MemcachedEngine.php

@@ -107,7 +107,11 @@ class MemcachedEngine extends CacheEngine {
 			return true;
 		}
 
-		$this->_Memcached = new Memcached($this->settings['persistent'] ? (string)$this->settings['persistent'] : null);
+		if (!$this->settings['persistent']) {
+			$this->_Memcached = new Memcached();
+		} else {
+			$this->_Memcached = new Memcached((string)$this->settings['persistent']);
+		}
 		$this->_setOptions();
 
 		if (count($this->_Memcached->getServerList())) {

+ 4 - 3
lib/Cake/Model/Datasource/Database/Postgres.php

@@ -46,6 +46,7 @@ class Postgres extends DboSource {
 		'schema' => 'public',
 		'port' => 5432,
 		'encoding' => '',
+		'sslmode' => 'allow',
 		'flags' => array()
 	);
 
@@ -118,7 +119,7 @@ class Postgres extends DboSource {
 
 		try {
 			$this->_connection = new PDO(
-				"pgsql:host={$config['host']};port={$config['port']};dbname={$config['database']}",
+				"pgsql:host={$config['host']};port={$config['port']};dbname={$config['database']};sslmode={$config['sslmode']}",
 				$config['login'],
 				$config['password'],
 				$flags
@@ -353,8 +354,8 @@ class Postgres extends DboSource {
 		if ($this->execute('DELETE FROM ' . $this->fullTableName($table))) {
 			if (isset($this->_sequenceMap[$table]) && $reset != true) {
 				foreach ($this->_sequenceMap[$table] as $sequence) {
-					list($schema, $sequence) = explode('.', $sequence);
-					$this->_execute("ALTER SEQUENCE \"{$schema}\".\"{$sequence}\" RESTART WITH 1");
+					$quoted = $this->name($sequence);
+					$this->_execute("ALTER SEQUENCE {$quoted} RESTART WITH 1");
 				}
 			}
 			return true;

+ 1 - 1
lib/Cake/Model/Datasource/DboSource.php

@@ -181,7 +181,7 @@ class DboSource extends DataSource {
  *
  * @var array
  */
-	protected $_sqlOps = array('like', 'ilike', 'or', 'not', 'in', 'between', 'regexp', 'similar to');
+	protected $_sqlOps = array('like', 'ilike', 'rlike', 'or', 'not', 'in', 'between', 'regexp', 'similar to');
 
 /**
  * Indicates the level of nested transactions

+ 3 - 1
lib/Cake/Network/CakeResponse.php

@@ -1510,7 +1510,9 @@ class CakeResponse {
 	protected function _flushBuffer() {
 		//@codingStandardsIgnoreStart
 		@flush();
-		@ob_flush();
+		if (ob_get_level()) {
+			@ob_flush();
+		}
 		//@codingStandardsIgnoreEnd
 	}
 

+ 1 - 1
lib/Cake/Network/Email/CakeEmail.php

@@ -1359,7 +1359,7 @@ class CakeEmail {
 		$cut = ($wrapLength == CakeEmail::LINE_LENGTH_MUST);
 
 		foreach ($lines as $line) {
-			if (empty($line)) {
+			if (empty($line) && $line !== '0') {
 				$formatted[] = '';
 				continue;
 			}

+ 3 - 3
lib/Cake/Network/Http/HttpSocket.php

@@ -907,11 +907,10 @@ class HttpSocket extends CakeSocket {
  * Builds a request line according to HTTP/1.1 specs. Activate quirks mode to work outside specs.
  *
  * @param array $request Needs to contain a 'uri' key. Should also contain a 'method' key, otherwise defaults to GET.
- * @param string $versionToken The version token to use, defaults to HTTP/1.1
  * @return string Request line
  * @throws SocketException
  */
-	protected function _buildRequestLine($request = array(), $versionToken = 'HTTP/1.1') {
+	protected function _buildRequestLine($request = array()) {
 		$asteriskMethods = array('OPTIONS');
 
 		if (is_string($request)) {
@@ -937,7 +936,8 @@ class HttpSocket extends CakeSocket {
 		if (!$this->quirksMode && $request['uri'] === '*' && !in_array($request['method'], $asteriskMethods)) {
 			throw new SocketException(__d('cake_dev', 'HttpSocket::_buildRequestLine - The "*" asterisk character is only allowed for the following methods: %s. Activate quirks mode to work outside of HTTP/1.1 specs.', implode(',', $asteriskMethods)));
 		}
-		return $request['method'] . ' ' . $request['uri'] . ' ' . $versionToken . "\r\n";
+		$version = isset($request['version']) ? $request['version'] : '1.1';
+		return $request['method'] . ' ' . $request['uri'] . ' HTTP/' . $version . "\r\n";
 	}
 
 /**

+ 12 - 11
lib/Cake/Network/Http/HttpSocketResponse.php

@@ -221,28 +221,29 @@ class HttpSocketResponse implements ArrayAccess {
 		$chunkLength = null;
 
 		while ($chunkLength !== 0) {
-			if (!preg_match('/^([0-9a-f]+) *(?:;(.+)=(.+))?(?:\r\n|\n)/iU', $body, $match)) {
-				throw new SocketException(__d('cake_dev', 'HttpSocket::_decodeChunkedBody - Could not parse malformed chunk.'));
+			if (!preg_match('/^([0-9a-f]+)[ ]*(?:;(.+)=(.+))?(?:\r\n|\n)/iU', $body, $match)) {
+				// Handle remaining invalid data as one big chunk.
+				preg_match('/^(.*?)\r\n/', $body, $invalidMatch);
+				$length = isset($invalidMatch[1]) ? strlen($invalidMatch[1]) : 0;
+				$match = array(
+					0 => '',
+					1 => dechex($length)
+				);
 			}
-
 			$chunkSize = 0;
 			$hexLength = 0;
-			$chunkExtensionValue = '';
 			if (isset($match[0])) {
 				$chunkSize = $match[0];
 			}
 			if (isset($match[1])) {
 				$hexLength = $match[1];
 			}
-			if (isset($match[3])) {
-				$chunkExtensionValue = $match[3];
-			}
 
-			$body = substr($body, strlen($chunkSize));
 			$chunkLength = hexdec($hexLength);
-			$chunk = substr($body, 0, $chunkLength);
-			$decodedBody .= $chunk;
-			if ($chunkLength !== 0) {
+			$body = substr($body, strlen($chunkSize));
+
+			$decodedBody .= substr($body, 0, $chunkLength);
+			if ($chunkLength) {
 				$body = substr($body, $chunkLength + strlen("\r\n"));
 			}
 		}

+ 4 - 0
lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php

@@ -2384,6 +2384,10 @@ SQL;
 		$expected = " WHERE ((`User`.`user` = 'mariano') OR (`User`.`user` = 'nate'))";
 		$this->assertEquals($expected, $result);
 
+		$result = $this->Dbo->conditions(array('User.user RLIKE' => 'mariano|nate'));
+		$expected = " WHERE `User`.`user` RLIKE 'mariano|nate'";
+		$this->assertEquals($expected, $result);
+
 		$result = $this->Dbo->conditions(array('or' => array(
 			'score BETWEEN ? AND ?' => array('4', '5'), 'rating >' => '20'
 		)));

+ 19 - 0
lib/Cake/Test/Case/Network/Email/CakeEmailTest.php

@@ -2417,6 +2417,25 @@ HTML;
 	}
 
 /**
+ * testZeroOnlyLinesNotBeingEmptied()
+ *
+ * @return void
+ */
+	public function testZeroOnlyLinesNotBeingEmptied() {
+		$message = "Lorem\r\n0\r\n0\r\nipsum";
+
+		$this->CakeEmail->reset();
+		$this->CakeEmail->transport('Debug');
+		$this->CakeEmail->from('cake@cakephp.org');
+		$this->CakeEmail->to('cake@cakephp.org');
+		$this->CakeEmail->subject('Wordwrap Test');
+		$this->CakeEmail->config(array('empty'));
+		$result = $this->CakeEmail->send($message);
+		$expected = "{$message}\r\n\r\n";
+		$this->assertEquals($expected, $result['message']);
+	}
+
+/**
  * CakeEmailTest::assertLineLengths()
  *
  * @param string $message

+ 3 - 3
lib/Cake/Test/Case/Network/Http/HttpResponseTest.php

@@ -15,7 +15,6 @@
  * @since         CakePHP(tm) v 1.2.0.4206
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
  */
-
 App::uses('HttpResponse', 'Network/Http');
 
 /**
@@ -453,12 +452,13 @@ class HttpResponseTest extends CakeTestCase {
 /**
  * testDecodeChunkedBodyError method
  *
- * @expectedException SocketException
  * @return void
  */
 	public function testDecodeChunkedBodyError() {
 		$encoded = "19\r\nThis is a chunked message\r\nE\r\n\nThat is cool\n\r\n";
-		$this->HttpResponse->decodeChunkedBody($encoded);
+		$result = $this->HttpResponse->decodeChunkedBody($encoded);
+		$expected = "This is a chunked message\nThat is cool\n";
+		$this->assertEquals($expected, $result['body']);
 	}
 
 /**

+ 16 - 5
lib/Cake/Test/Case/Network/Http/HttpSocketTest.php

@@ -138,8 +138,8 @@ class TestHttpSocket extends HttpSocket {
  * @param string $versionToken The version token to use, defaults to HTTP/1.1
  * @return string Request line
  */
-	public function buildRequestLine($request = array(), $versionToken = 'HTTP/1.1') {
-		return parent::_buildRequestLine($request, $versionToken);
+	public function buildRequestLine($request = array()) {
+		return parent::_buildRequestLine($request);
 	}
 
 /**
@@ -529,6 +529,7 @@ class HttpSocketTest extends CakeTestCase {
 			),
 			array(
 				'request' => array(
+					'version' => '1.0',
 					'method' => 'POST',
 					'uri' => 'https://www.cakephp.org/posts/add',
 					'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today'),
@@ -536,6 +537,8 @@ class HttpSocketTest extends CakeTestCase {
 				),
 				'expectation' => array(
 					'request' => array(
+						'version' => '1.0',
+						'line' => "POST /posts/add HTTP/1.0\r\n",
 						'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\nCookie: foo=bar\r\n",
 						'cookies' => array(
 							'foo' => array('value' => 'bar'),
@@ -1297,9 +1300,6 @@ class HttpSocketTest extends CakeTestCase {
 		$r = $this->Socket->buildRequestLine($request);
 		$this->assertEquals("GET /search?q=socket HTTP/1.1\r\n", $r);
 
-		$r = $this->Socket->buildRequestLine($request, 'CAKE-HTTP/0.1');
-		$this->assertEquals("GET /search?q=socket CAKE-HTTP/0.1\r\n", $r);
-
 		$request = array('method' => 'OPTIONS', 'uri' => '*');
 		$r = $this->Socket->buildRequestLine($request);
 		$this->assertEquals("OPTIONS * HTTP/1.1\r\n", $r);
@@ -1311,6 +1311,17 @@ class HttpSocketTest extends CakeTestCase {
 
 		$r = $this->Socket->buildRequestLine("GET * HTTP/1.1\r\n");
 		$this->assertEquals("GET * HTTP/1.1\r\n", $r);
+
+		$request = array(
+			'version' => '1.0',
+			'method' => 'GET',
+			'uri' => array(
+				'path' => '/search',
+				'query' => array('q' => 'socket')
+			)
+		);
+		$r = $this->Socket->buildRequestLine($request);
+		$this->assertEquals("GET /search?q=socket HTTP/1.0\r\n", $r);
 	}
 
 /**

+ 16 - 0
lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php

@@ -900,6 +900,22 @@ class HtmlHelperTest extends CakeTestCase {
 	}
 
 /**
+ * Resource names must be treated differently for css() and script()
+ *
+ * @return void
+ */
+	public function testBufferedCssAndScriptWithIdenticalResourceName() {
+		$this->View->expects($this->at(0))
+			->method('append')
+			->with('css', $this->stringContains('test.min.css'));
+		$this->View->expects($this->at(1))
+			->method('append')
+			->with('script', $this->stringContains('test.min.js'));
+		$this->Html->css('test.min', array('inline' => false));
+		$this->Html->script('test.min', array('inline' => false));
+	}
+
+/**
  * test timestamp enforcement for script tags.
  *
  * @return void

+ 3 - 1
lib/Cake/TestSuite/CakeTestRunner.php

@@ -15,7 +15,9 @@
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
  */
 
-require_once 'PHPUnit/TextUI/TestRunner.php';
+if (!defined('__PHPUNIT_PHAR__')) {
+	require_once 'PHPUnit/TextUI/TestRunner.php';
+}
 
 App::uses('CakeFixtureManager', 'TestSuite/Fixture');
 

+ 3 - 1
lib/Cake/TestSuite/CakeTestSuiteCommand.php

@@ -16,7 +16,9 @@
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
  */
 
-require_once 'PHPUnit/TextUI/Command.php';
+if (!defined('__PHPUNIT_PHAR__')) {
+	require_once 'PHPUnit/TextUI/Command.php';
+}
 
 App::uses('CakeTestRunner', 'TestSuite');
 App::uses('CakeTestLoader', 'TestSuite');

+ 6 - 0
lib/Cake/TestSuite/CakeTestSuiteDispatcher.php

@@ -151,6 +151,12 @@ class CakeTestSuiteDispatcher {
 			} elseif (is_dir($vendor . DS . 'PHPUnit')) {
 				ini_set('include_path', $vendor . PATH_SEPARATOR . ini_get('include_path'));
 				break;
+			} elseif (is_file($vendor . DS . 'phpunit.phar')) {
+				$backup = $GLOBALS['_SERVER']['SCRIPT_NAME'];
+				$GLOBALS['_SERVER']['SCRIPT_NAME'] = '-';
+				$included = include_once $vendor . DS . 'phpunit.phar';
+				$GLOBALS['_SERVER']['SCRIPT_NAME'] = $backup;
+				return $included;
 			}
 		}
 		include 'PHPUnit' . DS . 'Autoload.php';

+ 3 - 1
lib/Cake/TestSuite/Reporter/CakeBaseReporter.php

@@ -15,7 +15,9 @@
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
  */
 
-require_once 'PHPUnit/TextUI/ResultPrinter.php';
+if (!defined('__PHPUNIT_PHAR__')) {
+	require_once 'PHPUnit/TextUI/ResultPrinter.php';
+}
 
 /**
  * CakeBaseReporter contains common reporting features used in the CakePHP Test suite

+ 4 - 4
lib/Cake/View/Helper/HtmlHelper.php

@@ -449,11 +449,11 @@ class HtmlHelper extends AppHelper {
 			return;
 		}
 
-		if ($options['once'] && isset($this->_includedAssets[$path])) {
+		if ($options['once'] && isset($this->_includedAssets[__METHOD__][$path])) {
 			return '';
 		}
 		unset($options['once']);
-		$this->_includedAssets[$path] = true;
+		$this->_includedAssets[__METHOD__][$path] = true;
 
 		if (strpos($path, '//') !== false) {
 			$url = $path;
@@ -552,10 +552,10 @@ class HtmlHelper extends AppHelper {
 			}
 			return null;
 		}
-		if ($options['once'] && isset($this->_includedAssets[$url])) {
+		if ($options['once'] && isset($this->_includedAssets[__METHOD__][$url])) {
 			return null;
 		}
-		$this->_includedAssets[$url] = true;
+		$this->_includedAssets[__METHOD__][$url] = true;
 
 		if (strpos($url, '//') === false) {
 			$url = $this->assetUrl($url, $options + array('pathPrefix' => Configure::read('App.jsBaseUrl'), 'ext' => '.js'));

+ 2 - 2
lib/Cake/bootstrap.php

@@ -148,6 +148,8 @@ App::uses('Cache', 'Cache');
 App::uses('Object', 'Core');
 App::uses('Multibyte', 'I18n');
 
+App::$bootstrapping = true;
+
 /**
  * Full URL prefix
  */
@@ -170,8 +172,6 @@ Configure::write('App.imageBaseUrl', IMAGES_URL);
 Configure::write('App.cssBaseUrl', CSS_URL);
 Configure::write('App.jsBaseUrl', JS_URL);
 
-App::$bootstrapping = true;
-
 Configure::bootstrap(isset($boot) ? $boot : true);
 
 if (function_exists('mb_internal_encoding')) {