Skip to content

Commit c2d701e

Browse files
committedJul 30, 2012
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
1 parent 8945fcc commit c2d701e

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed
 

‎core/custom_field_api.php

+15-3
Original file line numberDiff line numberDiff line change
@@ -1161,25 +1161,37 @@ function custom_field_validate( $p_field_id, $p_value ) {
11611161
$t_length = utf8_strlen( $p_value );
11621162
switch ($t_type) {
11631163
case CUSTOM_FIELD_TYPE_STRING:
1164+
# Empty fields are valid
1165+
if( $t_length == 0 ) {
1166+
break;
1167+
}
11641168
# Regular expression string validation
1165-
if( !is_blank( $t_valid_regexp ) && !is_blank( $p_value ) ) {
1169+
if( !is_blank( $t_valid_regexp ) ) {
11661170
$t_valid &= preg_match( "/$t_valid_regexp/", $p_value );
11671171
}
11681172
# Check the length of the string
11691173
$t_valid &= ( 0 == $t_length_min ) || ( $t_length >= $t_length_min );
11701174
$t_valid &= ( 0 == $t_length_max ) || ( $t_length <= $t_length_max );
11711175
break;
11721176
case CUSTOM_FIELD_TYPE_NUMERIC:
1173-
$t_valid &= ( $t_length == 0 ) || is_numeric( $p_value );
1177+
# Empty fields are valid
1178+
if( $t_length == 0 ) {
1179+
break;
1180+
}
1181+
$t_valid &= is_numeric( $p_value );
11741182

11751183
# Check the length of the number
11761184
$t_valid &= ( 0 == $t_length_min ) || ( $t_length >= $t_length_min );
11771185
$t_valid &= ( 0 == $t_length_max ) || ( $t_length <= $t_length_max );
11781186

11791187
break;
11801188
case CUSTOM_FIELD_TYPE_FLOAT:
1189+
# Empty fields are valid
1190+
if( $t_length == 0 ) {
1191+
break;
1192+
}
11811193
# Allow both integer and float numbers
1182-
$t_valid &= ( $t_length == 0 ) || is_numeric( $p_value ) || is_float( $p_value );
1194+
$t_valid &= is_numeric( $p_value ) || is_float( $p_value );
11831195

11841196
# Check the length of the number
11851197
$t_valid &= ( 0 == $t_length_min ) || ( $t_length >= $t_length_min );

0 commit comments

Comments
 (0)
Please sign in to comment.