Skip to content

Commit

Permalink
Properly convert POST parameters
Browse files Browse the repository at this point in the history
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 b0180f1
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions libraries/config/FormDisplay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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
Expand Down Expand Up @@ -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.