Commit 79810c3d authored by Hugh Davenport's avatar Hugh Davenport
Browse files

Fix whitespace issues with param_... functions



bug #838429

Basically param_... functions don't check for trailing whitespace
This patch fixes this by trimming the value after it retrieves it.

Also, the param_integer_list function says in the comment it allows
optional whitespace, but the regex expression used doesn't allow it.
This patch fixes that.

Also, the param_signed_integer function didn't check on the entire value
and you could have a value like "ab+10cd".
This patch alters the regex to capture the start and end of string ^ and $

Change-Id: Ic26cc257f0057b6b686fc8c2e3c789610e055507
Signed-off-by: default avatarHugh Davenport <hugh@catalyst.net.nz>
parent 279d965e
......@@ -1056,6 +1056,8 @@ function param_integer($name) {
list ($value, $defaultused) = call_user_func_array('_param_retrieve', $args);
$value = trim($value);
if ($defaultused) {
return $value;
}
......@@ -1087,11 +1089,13 @@ function param_signed_integer($name) {
list ($value, $defaultused) = call_user_func_array('_param_retrieve', $args);
$value = trim($value);
if ($defaultused) {
return $value;
}
if (preg_match('#[+-]?[0-9]+#', $value)) {
if (preg_match('/^[+-]?[0-9]+$/', $value)) {
return (int)$value;
}
else if ($value == '' && isset($args[1])) {
......@@ -1120,6 +1124,8 @@ function param_alpha($name) {
list ($value, $defaultused) = call_user_func_array('_param_retrieve', $args);
$value = trim($value);
if ($defaultused) {
return $value;
}
......@@ -1150,6 +1156,8 @@ function param_alphanum($name) {
list ($value, $defaultused) = call_user_func_array('_param_retrieve', $args);
$value = trim($value);
if ($defaultused) {
return $value;
}
......@@ -1180,6 +1188,8 @@ function param_alphanumext($name) {
list ($value, $defaultused) = call_user_func_array('_param_retrieve', $args);
$value = trim($value);
if ($defaultused) {
return $value;
}
......@@ -1211,6 +1221,8 @@ function param_integer_list($name) {
list ($value, $defaultused) = call_user_func_array('_param_retrieve', $args);
$value = trim($value);
if ($defaultused) {
return $value;
}
......@@ -1219,7 +1231,7 @@ function param_integer_list($name) {
return array();
}
if (preg_match('/^(\d+(,\d+)*)$/',$value)) {
if (preg_match('/^(\d+(\s*,\s*\d+)*)$/',$value)) {
return array_map('intval', explode(',', $value));
}
......@@ -1238,6 +1250,8 @@ function param_boolean($name) {
list ($value) = _param_retrieve($name, false);
$value = trim($value);
if (empty($value) || $value == 'off' || $value == 'no' || $value == 'false') {
return false;
}
......@@ -1261,6 +1275,8 @@ function param_imagesize($name) {
list ($value, $defaultused) = call_user_func_array('_param_retrieve', $args);
$value = trim($value);
if ($defaultused) {
return $value;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment