Commit 0043cc83 authored by Hugh Davenport's avatar Hugh Davenport
Browse files

Fix issue when param_... functions have default of null

Bug #872619

Regression from 79810c3d



Basically, a default parameter of null was given, then trim
was called, which made it into the string '' which then failed
the test is_null in the files it was used.

This reorders the functions so that the trim is called after
the test to see whether the default should be used. This means
that the default value is never trimmed, and can be null.

One exception to this, is the param_boolean which doesn't test
to see whether it is the default that is returned, so a check
is made first to see whether it is null.

Change-Id: I66d7253a8414dec7eb3ea67ebd363ea068a32012
Signed-off-by: default avatarHugh Davenport <hugh@catalyst.net.nz>
parent 53959d72
......@@ -1017,12 +1017,12 @@ function param_integer($name) {
list ($value, $defaultused) = call_user_func_array('_param_retrieve', $args);
$value = trim($value);
if ($defaultused) {
return $value;
}
$value = trim($value);
if (preg_match('/^\d+$/',$value)) {
return (int)$value;
}
......@@ -1050,12 +1050,12 @@ function param_signed_integer($name) {
list ($value, $defaultused) = call_user_func_array('_param_retrieve', $args);
$value = trim($value);
if ($defaultused) {
return $value;
}
$value = trim($value);
if (preg_match('/^[+-]?[0-9]+$/', $value)) {
return (int)$value;
}
......@@ -1085,12 +1085,13 @@ function param_alpha($name) {
list ($value, $defaultused) = call_user_func_array('_param_retrieve', $args);
$value = trim($value);
if ($defaultused) {
return $value;
}
$value = trim($value);
if (preg_match('/^[a-zA-Z]+$/',$value)) {
return $value;
}
......@@ -1117,12 +1118,12 @@ function param_alphanum($name) {
list ($value, $defaultused) = call_user_func_array('_param_retrieve', $args);
$value = trim($value);
if ($defaultused) {
return $value;
}
$value = trim($value);
if (preg_match('/^[a-zA-Z0-9]+$/',$value)) {
return $value;
}
......@@ -1149,12 +1150,12 @@ function param_alphanumext($name) {
list ($value, $defaultused) = call_user_func_array('_param_retrieve', $args);
$value = trim($value);
if ($defaultused) {
return $value;
}
$value = trim($value);
if (preg_match('/^[a-zA-Z0-9_.-]+$/',$value)) {
return $value;
}
......@@ -1182,12 +1183,12 @@ function param_integer_list($name) {
list ($value, $defaultused) = call_user_func_array('_param_retrieve', $args);
$value = trim($value);
if ($defaultused) {
return $value;
}
$value = trim($value);
if ($value == '') {
return array();
}
......@@ -1211,7 +1212,9 @@ function param_boolean($name) {
list ($value) = _param_retrieve($name, false);
$value = trim($value);
if (!is_null($value)) {
$value = trim($value);
}
if (empty($value) || $value == 'off' || $value == 'no' || $value == 'false') {
return false;
......@@ -1236,12 +1239,12 @@ function param_imagesize($name) {
list ($value, $defaultused) = call_user_func_array('_param_retrieve', $args);
$value = trim($value);
if ($defaultused) {
return $value;
}
$value = trim($value);
if (!preg_match('/\d+x\d+/', $value)) {
throw new ParameterException('Invalid size for image specified');
}
......
Supports Markdown
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