Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9094a34

Browse files
committedJul 30, 2012
Custom field validation should pass when empty and min length > 0
Fix for #12029 (commit 9c71d4f) 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 79e4d02 commit 9094a34

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed
 

‎core/custom_field_api.php

+19-7
Original file line numberDiff line numberDiff line change
@@ -1148,30 +1148,42 @@ function custom_field_validate( $p_field_id, $p_value ) {
11481148
$t_length = utf8_strlen( $p_value );
11491149
switch ($t_type) {
11501150
case CUSTOM_FIELD_TYPE_STRING:
1151+
# Empty fields are valid
Has a conversation. Original line has a conversation.
1152+
if( $t_length == 0 ) {
1153+
break;
1154+
}
11511155
# Regular expression string validation
1152-
if( !is_blank( $t_valid_regexp ) && !is_blank( $p_value ) ) {
1156+
if( !is_blank( $t_valid_regexp ) ) {
11531157
$t_valid &= preg_match( "/$t_valid_regexp/", $p_value );
11541158
}
11551159
# Check the length of the string
11561160
$t_valid &= ( 0 == $t_length_min ) || ( $t_length >= $t_length_min );
11571161
$t_valid &= ( 0 == $t_length_max ) || ( $t_length <= $t_length_max );
11581162
break;
11591163
case CUSTOM_FIELD_TYPE_NUMERIC:
1160-
$t_valid &= ( $t_length == 0 ) || is_numeric( $p_value );
1161-
1164+
# Empty fields are valid
1165+
if( $t_length == 0 ) {
1166+
break;
1167+
}
1168+
$t_valid &= is_numeric( $p_value );
1169+
11621170
# Check the length of the number
11631171
$t_valid &= ( 0 == $t_length_min ) || ( $t_length >= $t_length_min );
11641172
$t_valid &= ( 0 == $t_length_max ) || ( $t_length <= $t_length_max );
1165-
1173+
11661174
break;
11671175
case CUSTOM_FIELD_TYPE_FLOAT:
1176+
# Empty fields are valid
1177+
if( $t_length == 0 ) {
1178+
break;
1179+
}
11681180
# Allow both integer and float numbers
1169-
$t_valid &= ( $t_length == 0 ) || is_numeric( $p_value ) || is_float( $p_value );
1170-
1181+
$t_valid &= is_numeric( $p_value ) || is_float( $p_value );
1182+
11711183
# Check the length of the number
11721184
$t_valid &= ( 0 == $t_length_min ) || ( $t_length >= $t_length_min );
11731185
$t_valid &= ( 0 == $t_length_max ) || ( $t_length <= $t_length_max );
1174-
1186+
11751187
break;
11761188
case CUSTOM_FIELD_TYPE_DATE:
11771189
# gpc_get_cf for date returns the value from strftime

0 commit comments

Comments
 (0)
Please sign in to comment.