From 261a99c0e3fbb78dc2a80d746fecd73e89669061 Mon Sep 17 00:00:00 2001 From: Val Bancer Date: Sat, 17 Nov 2018 20:27:05 +0100 Subject: [PATCH 1/7] Improve documentation and code style --- lib/Cake/Controller/Controller.php | 6 +++--- lib/Cake/Network/CakeResponse.php | 24 ++++++++++++++---------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index 20d5e7843..19e54692d 100644 --- a/lib/Cake/Controller/Controller.php +++ b/lib/Cake/Controller/Controller.php @@ -712,7 +712,7 @@ class Controller extends CakeObject implements CakeEventListener { * 800 => 'Unexpected Minotaur' * )); // sets these new values, and returns true * - * @return array Associative array of the HTTP codes as keys, and the message + * @return array|null|true Associative array of the HTTP codes as keys, and the message * strings as values, or null of the given $code does not exist. * @deprecated 3.0.0 Since 2.4. Will be removed in 3.0. Use CakeResponse::httpCodes(). */ @@ -757,7 +757,7 @@ class Controller extends CakeObject implements CakeEventListener { * * @param string|array $url A string or array-based URL pointing to another location within the app, * or an absolute URL - * @param int|array|null $status HTTP status code (eg: 301). Defaults to 302 when null is passed. + * @param int|array|null|string $status HTTP status code (eg: 301). Defaults to 302 when null is passed. * @param bool $exit If true, exit() will be called after the redirect * @return CakeResponse|null * @triggers Controller.beforeRedirect $this, array($url, $status, $exit) @@ -905,7 +905,7 @@ class Controller extends CakeObject implements CakeEventListener { * * `$errors = $this->validateErrors($this->Article, $this->User);` * - * @return array Validation errors, or false if none + * @return array|false Validation errors, or false if none * @deprecated 3.0.0 This method will be removed in 3.0 */ public function validateErrors() { diff --git a/lib/Cake/Network/CakeResponse.php b/lib/Cake/Network/CakeResponse.php index 5e1df6df6..4aa7eb076 100644 --- a/lib/Cake/Network/CakeResponse.php +++ b/lib/Cake/Network/CakeResponse.php @@ -374,7 +374,7 @@ class CakeResponse { * Holds all the cache directives that will be converted * into headers when sending the request * - * @var string + * @var array */ protected $_cacheDirectives = array(); @@ -672,8 +672,9 @@ class CakeResponse { * * For more on HTTP status codes see: http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.1 * - * @return mixed associative array of the HTTP codes as keys, and the message - * strings as values, or null of the given $code does not exist. + * @return array|null|true associative array of the HTTP codes as keys, and the message + * strings as values, or null of the given $code does not exist. `true` if `$code` is + * an array of valid codes. * @throws CakeException If an attempt is made to add an invalid status code */ public function httpCodes($code = null) { @@ -717,7 +718,7 @@ class CakeResponse { * * e.g `type(array('jpg' => 'text/plain'));` * - * @param string $contentType Content type key. + * @param array|string $contentType Content type key. * @return mixed current content type or false if supplied an invalid content type */ public function type($contentType = null) { @@ -854,7 +855,7 @@ class CakeResponse { } $this->maxAge($time); - if (!$time) { + if ($time === null) { $this->_setCacheControl(); } return (bool)$public; @@ -1160,7 +1161,11 @@ class CakeResponse { * @return bool whether the response was marked as not modified or not. */ public function checkNotModified(CakeRequest $request) { - $etags = preg_split('/\s*,\s*/', $request->header('If-None-Match'), null, PREG_SPLIT_NO_EMPTY); + $ifNoneMatchHeader = $request->header('If-None-Match'); + $etags = array(); + if (is_string($ifNoneMatchHeader)) { + $etags = preg_split('/\s*,\s*/', $ifNoneMatchHeader, null, PREG_SPLIT_NO_EMPTY); + } $modifiedSince = $request->header('If-Modified-Since'); $checks = array(); if ($responseTag = $this->etag()) { @@ -1224,7 +1229,7 @@ class CakeResponse { * * `$this->cookie((array) $options)` * - * @param array $options Either null to get all cookies, string for a specific cookie + * @param array|string $options Either null to get all cookies, string for a specific cookie * or array to set cookie. * @return mixed */ @@ -1312,8 +1317,7 @@ class CakeResponse { $result[] = array('preg' => '@.@', 'original' => '*'); continue; } - - $original = $preg = $domain; + $original = $domain; if (strpos($domain, '://') === false) { $preg = ($requestIsSSL ? 'https://' : 'http://') . $domain; } @@ -1464,7 +1468,7 @@ class CakeResponse { $file->open('rb'); $end = $start = false; - if ($range) { + if (!empty($range)) { list($start, $end) = $range; } if ($start !== false) { From 509accc421cd0e10f9172fafe4d066ac013a182e Mon Sep 17 00:00:00 2001 From: Val Bancer Date: Sat, 17 Nov 2018 20:55:42 +0100 Subject: [PATCH 2/7] Improve code style --- lib/Cake/Controller/Component/RequestHandlerComponent.php | 6 ++++-- lib/Cake/Network/CakeResponse.php | 3 --- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Controller/Component/RequestHandlerComponent.php b/lib/Cake/Controller/Component/RequestHandlerComponent.php index 6b1588bd6..df6ca78d0 100644 --- a/lib/Cake/Controller/Component/RequestHandlerComponent.php +++ b/lib/Cake/Controller/Component/RequestHandlerComponent.php @@ -271,8 +271,10 @@ class RequestHandlerComponent extends Component { } if (!empty($status)) { $statusCode = $this->response->httpCodes($status); - $code = key($statusCode); - $this->response->statusCode($code); + if (is_array($statusCode)) { + $code = key($statusCode); + $this->response->statusCode($code); + } } $this->response->body($this->requestAction($url, array('return', 'bare' => false))); $this->response->send(); diff --git a/lib/Cake/Network/CakeResponse.php b/lib/Cake/Network/CakeResponse.php index 4aa7eb076..c172a78b7 100644 --- a/lib/Cake/Network/CakeResponse.php +++ b/lib/Cake/Network/CakeResponse.php @@ -1318,9 +1318,6 @@ class CakeResponse { continue; } $original = $domain; - if (strpos($domain, '://') === false) { - $preg = ($requestIsSSL ? 'https://' : 'http://') . $domain; - } $preg = '@' . str_replace('*', '.*', $domain) . '@'; $result[] = compact('original', 'preg'); } From 92e9277d2090c08d8476145f51875cccea1f0384 Mon Sep 17 00:00:00 2001 From: Val Bancer Date: Sun, 18 Nov 2018 16:24:25 +0100 Subject: [PATCH 3/7] Improve code style --- lib/Cake/Network/CakeRequest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index 735024635..ebc2138ac 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -246,6 +246,7 @@ class CakeRequest implements ArrayAccess { * @return string URI The CakePHP request path that is being accessed. */ protected function _url() { + $uri = ''; if (!empty($_SERVER['PATH_INFO'])) { return $_SERVER['PATH_INFO']; } elseif (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '://') === false) { From cb1d80fda18003f451518ebb0baa0b5010020bd3 Mon Sep 17 00:00:00 2001 From: Val Bancer Date: Sun, 18 Nov 2018 17:13:11 +0100 Subject: [PATCH 4/7] Improve documentation --- lib/Cake/Network/CakeResponse.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Network/CakeResponse.php b/lib/Cake/Network/CakeResponse.php index c172a78b7..5fd1ac71b 100644 --- a/lib/Cake/Network/CakeResponse.php +++ b/lib/Cake/Network/CakeResponse.php @@ -331,7 +331,7 @@ class CakeResponse { * Content type to send. This can be an 'extension' that will be transformed using the $_mimetypes array * or a complete mime-type * - * @var int + * @var string */ protected $_contentType = 'text/html'; @@ -718,8 +718,8 @@ class CakeResponse { * * e.g `type(array('jpg' => 'text/plain'));` * - * @param array|string $contentType Content type key. - * @return mixed current content type or false if supplied an invalid content type + * @param array|string|null $contentType Content type key. + * @return string|false current content type or false if supplied an invalid content type */ public function type($contentType = null) { if ($contentType === null) { From c00579153b29f66652f25b20169ae4bb22cc452e Mon Sep 17 00:00:00 2001 From: Val Bancer Date: Sun, 18 Nov 2018 18:22:19 +0100 Subject: [PATCH 5/7] Cast var to int for comparison --- lib/Cake/Network/CakeResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Network/CakeResponse.php b/lib/Cake/Network/CakeResponse.php index 5fd1ac71b..b8aa9e643 100644 --- a/lib/Cake/Network/CakeResponse.php +++ b/lib/Cake/Network/CakeResponse.php @@ -855,7 +855,7 @@ class CakeResponse { } $this->maxAge($time); - if ($time === null) { + if ((int)$time === 0) { $this->_setCacheControl(); } return (bool)$public; From addd538526a6420911dc8fa7382473da024b6cac Mon Sep 17 00:00:00 2001 From: Val Bancer Date: Sun, 18 Nov 2018 22:48:34 +0100 Subject: [PATCH 6/7] Fix invalid condition --- lib/Cake/Network/CakeResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Network/CakeResponse.php b/lib/Cake/Network/CakeResponse.php index b8aa9e643..556b43767 100644 --- a/lib/Cake/Network/CakeResponse.php +++ b/lib/Cake/Network/CakeResponse.php @@ -1465,7 +1465,7 @@ class CakeResponse { $file->open('rb'); $end = $start = false; - if (!empty($range)) { + if (is_array($range) && !empty($range)) { list($start, $end) = $range; } if ($start !== false) { From 0f2bbf505d82fd9cebaeaf451b60ddf0b25110dd Mon Sep 17 00:00:00 2001 From: Val Bancer Date: Tue, 11 Dec 2018 16:36:32 +0100 Subject: [PATCH 7/7] Adjust the check according to review comments --- lib/Cake/Network/CakeResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Network/CakeResponse.php b/lib/Cake/Network/CakeResponse.php index 556b43767..cd24b2aad 100644 --- a/lib/Cake/Network/CakeResponse.php +++ b/lib/Cake/Network/CakeResponse.php @@ -1465,7 +1465,7 @@ class CakeResponse { $file->open('rb'); $end = $start = false; - if (is_array($range) && !empty($range)) { + if ($range && is_array($range)) { list($start, $end) = $range; } if ($start !== false) {