View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0003530 | mantisbt | bugtracker | public | 2004-01-29 10:24 | 2004-02-06 16:15 |
| Reporter | gvacanti | Assigned To | vboctor | ||
| Priority | normal | Severity | minor | Reproducibility | always |
| Status | closed | Resolution | fixed | ||
| Product Version | 0.18.0 | ||||
| Summary | 0003530: Custom fields definitions are not validated | ||||
| Description | It is possible to enter a custom field with minlength > maxlength. When this is done and the custom field in question is used, it becomes impossible to submit any new reports or modify any existing reports. Error 1303 is the answer to any action. | ||||
| Tags | No tags attached. | ||||
| Attached Files | 3530_custom_fields_definitions_are_not_validated .diff (4,350 bytes)
Index: core/constant_inc.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/constant_inc.php,v
retrieving revision 1.8
diff -u -r1.8 constant_inc.php
--- core/constant_inc.php 11 Jan 2004 07:16:10 -0000 1.8
+++ core/constant_inc.php 3 Feb 2004 13:01:18 -0000
@@ -212,6 +212,7 @@
define( 'ERROR_CUSTOM_FIELD_NAME_NOT_UNIQUE', 1301 );
define( 'ERROR_CUSTOM_FIELD_IN_USE', 1302 );
define( 'ERROR_CUSTOM_FIELD_INVALID_VALUE', 1303 );
+ define( 'ERROR_CUSTOM_FIELD_INVALID_DEFINITION', 1304 );
# ERROR_LDAP_*
define( 'ERROR_LDAP_AUTH_FAILED', 1400 );
Index: core/custom_field_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/custom_field_api.php,v
retrieving revision 1.21
diff -u -r1.21 custom_field_api.php
--- core/custom_field_api.php 11 Jan 2004 07:16:10 -0000 1.21
+++ core/custom_field_api.php 3 Feb 2004 13:01:20 -0000
@@ -140,13 +140,19 @@
# --------------------
# Check to see whether the name is unique
# return false if a field with the name already exists, true otherwise
- function custom_field_is_name_unique( $p_name ) {
+ # if an id is specified, then the corresponding record is excluded from the
+ # uniqueness test.
+ function custom_field_is_name_unique( $p_name, $p_custom_field_id = null ) {
$c_name = db_prepare_string( $p_name );
$t_custom_field_table = config_get( 'mantis_custom_field_table' );
$query = "SELECT COUNT(*) FROM
$t_custom_field_table
WHERE name='$c_name'";
+ if ( $p_custom_field_id !== null ) {
+ $c_id = db_prepare_int( $p_custom_field_id );
+ $query .= " AND (id <> $c_id)";
+ }
$result = db_query( $query );
$count = db_result( $result );
@@ -226,7 +232,7 @@
# the definition are the default values and can be changes later
# return the ID of the new definition
function custom_field_create( $p_name ) {
- $c_name = db_prepare_string( $p_name );
+ $c_name = db_prepare_string( trim( $p_name ) );
if ( is_blank( $p_name ) ) {
trigger_error( ERROR_EMPTY_FIELD, ERROR );
@@ -251,7 +257,7 @@
# return true on success, false on failure
function custom_field_update( $p_field_id, $p_def_array ) {
$c_field_id = db_prepare_int( $p_field_id );
- $c_name = db_prepare_string( $p_def_array['name'] );
+ $c_name = db_prepare_string( trim( $p_def_array['name'] ) );
$c_type = db_prepare_int( $p_def_array['type'] );
$c_possible_values = db_prepare_string( $p_def_array['possible_values'] );
$c_default_value = db_prepare_string( $p_def_array['default_value'] );
@@ -262,6 +268,17 @@
$c_length_max = db_prepare_int( $p_def_array['length_max'] );
$c_advanced = db_prepare_bool( $p_def_array['advanced'] );
+ if ( ( is_blank( $c_name ) ) ||
+ ( $c_access_level_rw < $c_access_level_r ) ||
+ ( $c_length_min < 0 ) ||
+ ( ( $c_length_max != 0 ) && ( $c_length_min > $c_length_max ) ) ) {
+ trigger_error( ERROR_CUSTOM_FIELD_INVALID_DEFINITION, ERROR );
+ }
+
+ if ( !custom_field_is_name_unique( $c_name, $c_field_id ) ) {
+ trigger_error( ERROR_CUSTOM_FIELD_NAME_NOT_UNIQUE, ERROR );
+ }
+
$query = "UPDATE " .
config_get( 'mantis_custom_field_table' ).
" SET ";
Index: lang/strings_english.txt
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/lang/strings_english.txt,v
retrieving revision 1.145
diff -u -r1.145 strings_english.txt
--- lang/strings_english.txt 11 Jan 2004 07:16:11 -0000 1.145
+++ lang/strings_english.txt 3 Feb 2004 13:01:22 -0000
@@ -186,6 +186,7 @@
$MANTIS_ERROR[ERROR_CUSTOM_FIELD_NAME_NOT_UNIQUE] = 'This is a duplicate name.';
$MANTIS_ERROR[ERROR_CUSTOM_FIELD_IN_USE] = 'At least one project still uses this field.';
$MANTIS_ERROR[ERROR_CUSTOM_FIELD_INVALID_VALUE] = 'Invalid value for field';
+$MANTIS_ERROR[ERROR_CUSTOM_FIELD_INVALID_DEFINITION] = 'Invalid custom field definition';
$MANTIS_ERROR[ERROR_LDAP_AUTH_FAILED] = 'LDAP Authentication Failed';
$MANTIS_ERROR[ERROR_LDAP_SERVER_CONNECT_FAILED] = 'LDAP Server Connection Failed';
$MANTIS_ERROR[ERROR_LDAP_UPDATE_FAILED] = 'LDAP Record Update has failed.';
| ||||
|
Added the following checks on updating of custom fields:
|
|
|
Patch added and fixed in CVS. Will be included in next version. |
|
|
MantisBT: master 573016b6 2004-02-03 08:06 Details Diff |
Fix 0003530: Custom fields definitions are not validated. M core/constant_inc.php - Added constant for new custom field error (ERROR_CUSTOM_FIELD_INVALID_DEFINITION). M lang/strings_english.txt - Added English string for new custom field error (ERROR_CUSTOM_FIELD_INVALID_DEFINITION). M core/custom_field_api.php + Added the following checks on updating of custom fields: - Name is not blank. - Name is still unique - access level for read/write is smaller than or equal to access level for read. - Minimum length >= 0; - Maximum length is 0 (disabled), or greater than or equal to minimum length. git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/trunk@2292 <a class="text" href="/?p=mantisbt.git;a=object;h=f5dc347c">f5dc347c</a>-c33d-0410-90a0-b07cc1902cb9 |
Affected Issues 0003530 |
|
| mod - core/constant_inc.php | Diff File | ||
| mod - lang/strings_english.txt | Diff File | ||
| mod - doc/ChangeLog | Diff File | ||
| mod - core/custom_field_api.php | Diff File | ||