Move request conversion to generic code

Signed-off-by: Michal Čihař <michal@cihar.com>
This commit is contained in:
Michal Čihař 2016-06-17 09:31:22 +02:00
parent c9faf855a0
commit 8451a7a5d2
2 changed files with 19 additions and 19 deletions

View File

@ -4225,5 +4225,20 @@ class PMA_Util
}
return false;
}
/**
* 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);
}
}
?>

View File

@ -562,12 +562,12 @@ class FormDisplay
// cast variables to correct type
switch ($type) {
case 'double':
settype($this->_trimString($_POST[$key]), 'float');
settype(PMA_Util::requestString($_POST[$key]), 'float');
break;
case 'boolean':
case 'integer':
if ($_POST[$key] !== '') {
settype($this->_trimString($_POST[$key]), $type);
settype(PMA_Util::requestString($_POST[$key]), $type);
}
break;
case 'select':
@ -583,7 +583,7 @@ class FormDisplay
break;
case 'string':
case 'short_string':
$_POST[$key] = $this->_trimString($_POST[$key]);
$_POST[$key] = PMA_Util::requestString($_POST[$key]);
break;
case 'array':
// eliminate empty values and ensure we have an array
@ -592,7 +592,7 @@ class FormDisplay
: explode("\n", $_POST[$key]);
$_POST[$key] = array();
foreach ($post_values as $v) {
$v = $this->_trimString($v);
$v = PMA_Util::requestString($v);
if ($v !== '') {
$_POST[$key][] = $v;
}
@ -819,20 +819,5 @@ class FormDisplay
}
}
}
/**
* 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);
}
}
?>