View Issue Details

IDProjectCategoryView StatusLast Update
0027807mantisbtbugtrackerpublic2023-10-31 16:36
Reporterdregad Assigned Todregad  
PrioritynormalSeverityminorReproducibilityalways
Status assignedResolutionopen 
Target Version2.27.0 
Summary0027807: Prevent silent update of invalid enum fields when editing issue
Description

If the value of a field stored in the database is not valid per the associated Enum string, editing the issue will silently reset the field's selection list to the enum's first value.

The user may not notice this, and unwittingly update the field when saving other changes made to the Issue.

TagsNo tags attached.

Relationships

related to 0027351 assigneddregad Prevent updating Issue with invalid values for ETA and Projection 

Activities

dregad

dregad

2020-12-29 04:29

developer   ~0064858

The initial approach to fix this by simply adding the field's current value ($p_val parameter) to the select's options in print_enum_string_option_list() introduces a regression in at least 2 pages (view_all_bug_page.php and bug_report_page.php), causing @0@ to be displayed in the select.

Original patch attached for reference, but a smarter approach is needed.

0001-Prevent-silent-update-of-invalid-enum-field-values.patch (1,272 bytes)   
From c237c7baa3b140402e1c96b3eef0189b104782ea Mon Sep 17 00:00:00 2001
From: Damien Regad <dregad@mantisbt.org>
Date: Sat, 26 Sep 2020 23:34:53 +0200
Subject: [PATCH] Prevent silent update of invalid enum field values

If the value of a field stored in the database is not valid per the
associated Enum string, editing the issue will silently reset the
field's selection list to the enum's first value.

The user may not notice this, and unwittingly update the field when
saving other changes made to the Issue.

To prevent this, print_enum_string_option_list() has been modified to
add the field's current value to the select's options.

Fixes #27807
---
 core/print_api.php | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/core/print_api.php b/core/print_api.php
index 8f4cd4fdb..dff1f3f16 100644
--- a/core/print_api.php
+++ b/core/print_api.php
@@ -976,6 +976,9 @@ function print_enum_string_option_list( $p_enum_name, $p_val = 0 ) {
 	}
 
 	$t_enum_values = MantisEnum::getValues( $t_config_var_value );
+	if( !MantisEnum::hasValue( $t_config_var_value, $p_val ) ) {
+		array_unshift( $t_enum_values, $p_val );
+	}
 
 	foreach ( $t_enum_values as $t_key ) {
 		$t_label = MantisEnum::getLocalizedLabel( $t_config_var_value, $t_string_var, $t_key );
-- 
2.25.1