diff --git a/lib/Cake/Console/Shell.php b/lib/Cake/Console/Shell.php index ff4237529..c446b9cd3 100644 --- a/lib/Cake/Console/Shell.php +++ b/lib/Cake/Console/Shell.php @@ -30,6 +30,13 @@ App::uses('File', 'Utility'); */ class Shell extends Object { +/** + * Default error code + * + * @var int + */ + const CODE_ERROR = 1; + /** * Output constant making verbose shells. * @@ -580,7 +587,8 @@ class Shell extends Object { $result = $this->stdin->read(); if ($result === false) { - return $this->_stop(1); + $this->_stop(self::CODE_ERROR); + return self::CODE_ERROR; } $result = trim($result); @@ -726,7 +734,8 @@ class Shell extends Object { if (!empty($message)) { $this->err($message); } - return $this->_stop(1); + $this->_stop(self::CODE_ERROR); + return self::CODE_ERROR; } /** @@ -764,7 +773,8 @@ class Shell extends Object { if (strtolower($key) === 'q') { $this->out(__d('cake_console', 'Quitting.'), 2); - return $this->_stop(); + $this->_stop(); + return true; } elseif (strtolower($key) !== 'y') { $this->out(__d('cake_console', 'Skip `%s`', $path), 2); return false; diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index f14373370..8860425ce 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -173,9 +173,13 @@ class CakeRequest implements ArrayAccess { if (ini_get('magic_quotes_gpc') === '1') { $this->data = stripslashes_deep($this->data); } + + $override = null; if (env('HTTP_X_HTTP_METHOD_OVERRIDE')) { $this->data['_method'] = env('HTTP_X_HTTP_METHOD_OVERRIDE'); + $override = $this->data['_method']; } + $isArray = is_array($this->data); if ($isArray && isset($this->data['_method'])) { if (!empty($_SERVER)) { @@ -183,8 +187,14 @@ class CakeRequest implements ArrayAccess { } else { $_ENV['REQUEST_METHOD'] = $this->data['_method']; } + $override = $this->data['_method']; unset($this->data['_method']); } + + if ($override && !in_array($override, array('POST', 'PUT', 'PATCH', 'DELETE'))) { + $this->data = array(); + } + if ($isArray && isset($this->data['data'])) { $data = $this->data['data']; if (count($this->data) <= 1) { diff --git a/lib/Cake/Test/Case/Network/CakeRequestTest.php b/lib/Cake/Test/Case/Network/CakeRequestTest.php index b588565a5..7d1d0706c 100644 --- a/lib/Cake/Test/Case/Network/CakeRequestTest.php +++ b/lib/Cake/Test/Case/Network/CakeRequestTest.php @@ -2444,6 +2444,24 @@ XML; $request->allowMethod('POST'); } +/** + * Tests that overriding the method to GET will clean all request + * data, to better simulate a GET request. + * + * @return void + */ + public function testMethodOverrideEmptyData() { + $_POST = array('_method' => 'GET', 'foo' => 'bar'); + $_SERVER['REQUEST_METHOD'] = 'PUT'; + $request = new CakeRequest('/posts/edit/1'); + $this->assertEmpty($request->data); + + $_POST = array('foo' => 'bar'); + $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'GET'; + $request = new CakeRequest('/posts/edit/1'); + $this->assertEmpty($request->data); + } + /** * loadEnvironment method *