From 9a1a31174b906988d230cd6de4f855328ce132d7 Mon Sep 17 00:00:00 2001 From: Victor Shvets Date: Fri, 26 Aug 2016 18:31:21 +0300 Subject: [PATCH 1/2] fix fatal error when $param is array --- app/code/community/Lesti/Fpc/Helper/Data.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/code/community/Lesti/Fpc/Helper/Data.php b/app/code/community/Lesti/Fpc/Helper/Data.php index 6fabdc6..b4e1063 100644 --- a/app/code/community/Lesti/Fpc/Helper/Data.php +++ b/app/code/community/Lesti/Fpc/Helper/Data.php @@ -217,6 +217,20 @@ public function canCacheRequest() $pair = array_map('trim', explode('=', $missParam)); $key = $pair[0]; $param = $request->getParam($key); + if (is_array($param)) { + $param = array_reduce( + $param, + function ($carry, $item) { + if (!is_array($item)) { + return $carry . $item; + } + + return ''; + }, + '' + ); + } + if ($param && isset($pair[1]) && preg_match($pair[1], $param)) { return false; } From 6548a9f7b81e6d9db31153a7b102620f50af9ad0 Mon Sep 17 00:00:00 2001 From: Victor Shvets Date: Mon, 29 Aug 2016 07:27:22 +0300 Subject: [PATCH 2/2] fix code style --- app/code/community/Lesti/Fpc/Helper/Data.php | 41 +++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/app/code/community/Lesti/Fpc/Helper/Data.php b/app/code/community/Lesti/Fpc/Helper/Data.php index b4e1063..1c6ae24 100644 --- a/app/code/community/Lesti/Fpc/Helper/Data.php +++ b/app/code/community/Lesti/Fpc/Helper/Data.php @@ -216,20 +216,7 @@ public function canCacheRequest() foreach ($missParams as $missParam) { $pair = array_map('trim', explode('=', $missParam)); $key = $pair[0]; - $param = $request->getParam($key); - if (is_array($param)) { - $param = array_reduce( - $param, - function ($carry, $item) { - if (!is_array($item)) { - return $carry . $item; - } - - return ''; - }, - '' - ); - } + $param = $this->_paramToString($request->getParam($key)); if ($param && isset($pair[1]) && preg_match($pair[1], $param)) { return false; @@ -272,4 +259,30 @@ public function getContentType(\Mage_Core_Controller_Response_Http $response) return 'text/html; charset=UTF-8'; } + + /** + * Transform array parameter to string to avoid error and make correct validation in regexp pattern + * + * @param mixed $param Input parameter + * + * @return mixed + */ + protected function _paramToString($param) + { + if (is_array($param)) { + $param = array_reduce( + $param, + function ($carry, $item) { + if (!is_array($item)) { + return $carry . $item; + } + + return ''; + }, + '' + ); + } + + return $param; + } }