diff --git a/lib/Cake/Cache/Engine/MemcachedEngine.php b/lib/Cake/Cache/Engine/MemcachedEngine.php index d00ce6133..12d4bc43f 100644 --- a/lib/Cake/Cache/Engine/MemcachedEngine.php +++ b/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())) { diff --git a/lib/Cake/Model/Datasource/Database/Postgres.php b/lib/Cake/Model/Datasource/Database/Postgres.php index 20e654202..87b26798f 100644 --- a/lib/Cake/Model/Datasource/Database/Postgres.php +++ b/lib/Cake/Model/Datasource/Database/Postgres.php @@ -354,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; diff --git a/lib/Cake/Network/CakeResponse.php b/lib/Cake/Network/CakeResponse.php index a7294adf4..ae071080b 100644 --- a/lib/Cake/Network/CakeResponse.php +++ b/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 } diff --git a/lib/Cake/Network/Email/CakeEmail.php b/lib/Cake/Network/Email/CakeEmail.php index eb5b3c9b7..61dc597b3 100644 --- a/lib/Cake/Network/Email/CakeEmail.php +++ b/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; } diff --git a/lib/Cake/Network/Http/HttpSocket.php b/lib/Cake/Network/Http/HttpSocket.php index e9a43d495..4e1f7e94a 100644 --- a/lib/Cake/Network/Http/HttpSocket.php +++ b/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"; } /** diff --git a/lib/Cake/Network/Http/HttpSocketResponse.php b/lib/Cake/Network/Http/HttpSocketResponse.php index 03474f385..99d875c31 100644 --- a/lib/Cake/Network/Http/HttpSocketResponse.php +++ b/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")); } } diff --git a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php index 23dd78bd6..1dc125fea 100644 --- a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php +++ b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php @@ -2416,6 +2416,25 @@ HTML; $this->assertEquals($expected, $result['message']); } +/** + * 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() * diff --git a/lib/Cake/Test/Case/Network/Http/HttpResponseTest.php b/lib/Cake/Test/Case/Network/Http/HttpResponseTest.php index 54493a6b8..502340094 100644 --- a/lib/Cake/Test/Case/Network/Http/HttpResponseTest.php +++ b/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']); } /** diff --git a/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php b/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php index 1b56f9881..6456a0c21 100644 --- a/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php +++ b/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); } /** diff --git a/lib/Cake/TestSuite/CakeTestRunner.php b/lib/Cake/TestSuite/CakeTestRunner.php index 8e2fc4730..3aafdc198 100644 --- a/lib/Cake/TestSuite/CakeTestRunner.php +++ b/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'); diff --git a/lib/Cake/TestSuite/CakeTestSuiteCommand.php b/lib/Cake/TestSuite/CakeTestSuiteCommand.php index 363a0057a..c4134c535 100644 --- a/lib/Cake/TestSuite/CakeTestSuiteCommand.php +++ b/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'); diff --git a/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php b/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php index 725df5eb1..8b8b1e3ca 100644 --- a/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php +++ b/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'; diff --git a/lib/Cake/TestSuite/Reporter/CakeBaseReporter.php b/lib/Cake/TestSuite/Reporter/CakeBaseReporter.php index 3974bee2b..c89ead4df 100644 --- a/lib/Cake/TestSuite/Reporter/CakeBaseReporter.php +++ b/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 diff --git a/lib/Cake/bootstrap.php b/lib/Cake/bootstrap.php index 303d36083..4ad77a21b 100644 --- a/lib/Cake/bootstrap.php +++ b/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')) {