Permalink
Browse files

Custom field validation should pass when empty and min length > 0

Fix for #12029 (commit dd286bf)
introduced a regression in the validation of numeric custom fields when
the field's minimum length is greater than 0 and the data being
validated is empty. This prevents e.g. reporting of new issues with a
hidden custom field, or updating issues having a non-required, empty
field.

This commit resolves the problem by passing validation when the field is
empty. This should not cause problems for required fields, as that case
is covered by an earlier check in bug_report.php and bug_update.php.

Fixes #14516
  • Loading branch information...
1 parent 8945fcc commit c2d701e88c02247ef857bf460f834d157fae52ab @dregad dregad committed Jul 29, 2012
Showing with 15 additions and 3 deletions.
  1. +15 −3 core/custom_field_api.php
View
@@ -1161,25 +1161,37 @@ function custom_field_validate( $p_field_id, $p_value ) {
$t_length = utf8_strlen( $p_value );
switch ($t_type) {
case CUSTOM_FIELD_TYPE_STRING:
+ # Empty fields are valid
+ if( $t_length == 0 ) {
+ break;
+ }
# Regular expression string validation
- if( !is_blank( $t_valid_regexp ) && !is_blank( $p_value ) ) {
+ if( !is_blank( $t_valid_regexp ) ) {
$t_valid &= preg_match( "/$t_valid_regexp/", $p_value );
}
# Check the length of the string
$t_valid &= ( 0 == $t_length_min ) || ( $t_length >= $t_length_min );
$t_valid &= ( 0 == $t_length_max ) || ( $t_length <= $t_length_max );
break;
case CUSTOM_FIELD_TYPE_NUMERIC:
- $t_valid &= ( $t_length == 0 ) || is_numeric( $p_value );
+ # Empty fields are valid
+ if( $t_length == 0 ) {
+ break;
+ }
+ $t_valid &= is_numeric( $p_value );
# Check the length of the number
$t_valid &= ( 0 == $t_length_min ) || ( $t_length >= $t_length_min );
$t_valid &= ( 0 == $t_length_max ) || ( $t_length <= $t_length_max );
break;
case CUSTOM_FIELD_TYPE_FLOAT:
+ # Empty fields are valid
+ if( $t_length == 0 ) {
+ break;
+ }
# Allow both integer and float numbers
- $t_valid &= ( $t_length == 0 ) || is_numeric( $p_value ) || is_float( $p_value );
+ $t_valid &= is_numeric( $p_value ) || is_float( $p_value );
# Check the length of the number
$t_valid &= ( 0 == $t_length_min ) || ( $t_length >= $t_length_min );

0 comments on commit c2d701e

Please sign in to comment.