Skip to content
Permalink
Browse files

Properly convert POST parameters

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

Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information...
nijel committed Jun 17, 2016
1 parent 6c5d5ff commit b0180f18c828706af3a6800f0fb01a536d3ef8c7
Showing with 19 additions and 4 deletions.
  1. +19 −4 libraries/config/FormDisplay.php
@@ -639,12 +639,12 @@ public function save($forms, $allow_partial_save = true)
// 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 @@ public function save($forms, $allow_partial_save = true)
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 @@ private function _setComments($system_path, array &$opts)
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);
}
}

0 comments on commit b0180f1

Please sign in to comment.
You can’t perform that action at this time.