Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 9094a34d71f2bbf14bb57ff22035fa427da5adc5 1 parent 79e4d02
@dregad dregad authored
Showing with 19 additions and 7 deletions.
  1. +19 −7 core/custom_field_api.php
View
26 core/custom_field_api.php
@@ -1148,8 +1148,12 @@ 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
@atrol Collaborator
atrol added a note

This introduces another issue.
Now I am able to edit an issue and to clear a custom text field also when Min. Length is set > 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ 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
@@ -1157,21 +1161,29 @@ function custom_field_validate( $p_field_id, $p_value ) {
$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 );
$t_valid &= ( 0 == $t_length_max ) || ( $t_length <= $t_length_max );
-
+
break;
case CUSTOM_FIELD_TYPE_DATE:
# gpc_get_cf for date returns the value from strftime
@atrol

This introduces another issue.
Now I am able to edit an issue and to clear a custom text field also when Min. Length is set > 0

Please sign in to comment.
Something went wrong with that request. Please try again.