Properly convert POST parameters

We can get array instead of single parameter, so handle this gracefully.

Signed-off-by: Michal Čihař <michal@cihar.com>
This commit is contained in:
Michal Čihař 2016-06-17 09:09:16 +02:00
parent 6c5d5ffc7f
commit b0180f18c8

View File

@ -639,12 +639,12 @@ class FormDisplay
// cast variables to correct type
switch ($type) {
case 'double':
settype($_POST[$key], 'float');
settype($this->_trimString($_POST[$key]), 'float');
break;
case 'boolean':
case 'integer':
if ($_POST[$key] !== '') {
settype($_POST[$key], $type);
settype($this->_trimString($_POST[$key]), $type);
}
break;
case 'select':
@ -660,7 +660,7 @@ class FormDisplay
break;
case 'string':
case 'short_string':
$_POST[$key] = trim($_POST[$key]);
$_POST[$key] = $this->_trimString($_POST[$key]);
break;
case 'array':
// eliminate empty values and ensure we have an array
@ -876,10 +876,25 @@ class FormDisplay
private function _fillPostArrayParameters($post_values, $key)
{
foreach ($post_values as $v) {
$v = trim($v);
$v = $this->_trimString($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);
}
}