Skip to content

Commit

Permalink
Fix #16020: allow empty required custom fields
Browse files Browse the repository at this point in the history
This is a port of the following 1.2.x commits:
- 890c36e
- 7ab6eb3

See related issues #12619, #11684 for details
  • Loading branch information
dregad committed Jul 22, 2013
1 parent a01f234 commit 3d96905
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
14 changes: 6 additions & 8 deletions bug_report.php
Expand Up @@ -166,15 +166,13 @@
$t_def = custom_field_get_definition( $t_id );

# Produce an error if the field is required but wasn't posted
if ( !gpc_isset_custom_field( $t_id, $t_def['type'] ) &&
( $t_def['require_report'] ||
$t_def['type'] == CUSTOM_FIELD_TYPE_ENUM ||
$t_def['type'] == CUSTOM_FIELD_TYPE_LIST ||
$t_def['type'] == CUSTOM_FIELD_TYPE_MULTILIST ||
$t_def['type'] == CUSTOM_FIELD_TYPE_RADIO ) ) {
if( !gpc_isset_custom_field( $t_id, $t_def['type'] )
&& $t_def['require_report']
) {
error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
trigger_error( ERROR_EMPTY_FIELD, ERROR );
}

if ( !custom_field_validate( $t_id, gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], NULL ) ) ) {
error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR );
Expand Down Expand Up @@ -206,7 +204,7 @@

# Handle custom field submission
foreach( $t_related_custom_field_ids as $t_id ) {
# Do not set custom field value if user has no write access.
# Do not set custom field value if user has no write access
if( !custom_field_has_write_access( $t_id, $t_bug_id ) ) {
continue;
}
Expand Down Expand Up @@ -278,7 +276,7 @@
// log status and resolution changes if they differ from the default
if ( $t_bug_data->status != config_get('bug_submit_status') )
history_log_event($t_bug_id, 'status', config_get('bug_submit_status') );

if ( $t_bug_data->resolution != config_get('default_bug_resolution') )
history_log_event($t_bug_id, 'resolution', config_get('default_bug_resolution') );

Expand Down
11 changes: 9 additions & 2 deletions core/custom_field_api.php
Expand Up @@ -1073,12 +1073,12 @@ function custom_field_validate( $p_field_id, $p_value ) {
$t_valid &= ( $p_value == null ) || ( ( $p_value !== false ) && ( $p_value > 0 ) );
break;
case CUSTOM_FIELD_TYPE_CHECKBOX:
case CUSTOM_FIELD_TYPE_MULTILIST:
# Checkbox fields can hold a null value (when no checkboxes are ticked)
if( $p_value === '' ) {
break;
}
# If checkbox field value is not null then we need to validate it... (note: no "break" statement here!)
case CUSTOM_FIELD_TYPE_MULTILIST:
# If checkbox field value is not null then we need to validate it
$t_values = explode( '|', $p_value );
$t_possible_values = custom_field_prepare_possible_values( $row['possible_values'] );
$t_possible_values = explode( '|', $t_possible_values );
Expand All @@ -1088,6 +1088,13 @@ function custom_field_validate( $p_field_id, $p_value ) {
case CUSTOM_FIELD_TYPE_ENUM:
case CUSTOM_FIELD_TYPE_LIST:
case CUSTOM_FIELD_TYPE_RADIO:
# List fields can be empty (when they are not shown on the
# form, or shown with no default values and never clicked)
if( is_blank( $p_value ) ) {
break;
}

# If list field value is not empty then we need to validate it
$t_possible_values = custom_field_prepare_possible_values( $row['possible_values'] );
$t_values_arr = explode( '|', $t_possible_values );
$t_valid &= in_array( $p_value, $t_values_arr );
Expand Down

0 comments on commit 3d96905

Please sign in to comment.