From ef1493d9b4b5c89ff3ff9965068f3ebf5a3059bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 17 Jun 2016 09:31:22 +0200 Subject: [PATCH] Move request conversion to generic code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- libraries/Util.php | 15 +++++++++++++++ libraries/config/FormDisplay.php | 23 ++++------------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/libraries/Util.php b/libraries/Util.php index 9048376cd9..c36520c1f4 100644 --- a/libraries/Util.php +++ b/libraries/Util.php @@ -4997,5 +4997,20 @@ class Util return $result; } + + /** + * Converts given (request) paramter to string + * + * @param mixed $value Value to convert + * + * @return string + */ + public static function requestString($value) + { + while (is_array($value) || is_object($value)) { + $value = reset($value); + } + return trim((string)$value); + } } diff --git a/libraries/config/FormDisplay.php b/libraries/config/FormDisplay.php index aeff097624..78da6b3174 100644 --- a/libraries/config/FormDisplay.php +++ b/libraries/config/FormDisplay.php @@ -639,12 +639,12 @@ class FormDisplay // cast variables to correct type switch ($type) { case 'double': - settype($this->_trimString($_POST[$key]), 'float'); + settype(Util::requestString($_POST[$key]), 'float'); break; case 'boolean': case 'integer': if ($_POST[$key] !== '') { - settype($this->_trimString($_POST[$key]), $type); + settype(Util::requestString($_POST[$key]), $type); } break; case 'select': @@ -660,7 +660,7 @@ class FormDisplay break; case 'string': case 'short_string': - $_POST[$key] = $this->_trimString($_POST[$key]); + $_POST[$key] = Util::requestString($_POST[$key]); break; case 'array': // eliminate empty values and ensure we have an array @@ -876,25 +876,10 @@ class FormDisplay private function _fillPostArrayParameters($post_values, $key) { foreach ($post_values as $v) { - $v = $this->_trimString($v); + $v = Util::requestString($v); if ($v !== '') { $_POST[$key][] = $v; } } } - - /* - * Converts given (request) paramter to string - * - * @param mixed $value Value to convert - * - * @return string - */ - private function _trimString($value) - { - while (is_array($value)) { - $value = reset($value); - } - return trim((string)$value); - } }