View Issue Details

IDProjectCategoryView StatusLast Update
0008323mantisbtcustom fieldspublic2012-09-16 17:21
Reporterntbone Assigned Todregad  
PrioritynormalSeveritytweakReproducibilityalways
Status closedResolutionduplicate 
Product Version1.1.0a4 
Summary0008323: Spaces in custom fields
Description

If you have a custom field with spaces included and you add it as a column to the "View Issues" page the column is not sortable. When you click on the column nothing happens.

The reason for the problem is that the URL sent to sort by that column includes the space thus producing the wrong information. If one adds "urlencode" around the sorting field, the column becomes sortable again. This problem may also occur if you use the # sign. For example, we added a custom field called "Marketing #" but was unable to sort by it.

I fixed the problem

Steps To Reproduce
  1. Add a custom field like "Marketing #" or "Special priority"
  2. Modify/create "custom_functions_inc.php"
  3. Add the function "custom_function_override_get_columns_to_view"
  4. Add in the custom view to be seen. See the php file included with the report.
  5. Modify some existing issues to include the custom field.
  6. Go to view issues
  7. Try to sort by the custom field.
  8. Notice it does not sort.
Additional Information

The fix occurs in print_view_bug_sort_link. The problem is that the url created to sort the lists does not encode spaces or special characters.

TagsNo tags attached.
Attached Files
custom funciton code and fix.txt (3,919 bytes)   
	# --------------------
	# returns an array of the column names to be displayed.
	# The column names to use are those of the field names in the bug table.
	# In addition, you can use the following:
	# - "selection" for selection checkboxes.
	# - "edit" for icon to open the edit page.
	# - "custom_xxxx" were xxxx is the name of the custom field that is valid for the
	#   current project.  In case of "All Projects, the field will be empty where it is
	#   not applicable.
	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
	function custom_function_override_get_columns_to_view( $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
		$t_columns = array();

		if ( $p_columns_target == COLUMNS_TARGET_CSV_PAGE ) {
			$t_columns[] = 'id'; // localized: 'id',
			$t_columns[] = 'project_id'; // 'email_project'
			$t_columns[] = 'reporter_id'; // 'reporter'
			$t_columns[] = 'handler_id'; // 'assigned_to'
			$t_columns[] = 'priority'; // 'priority'
			$t_columns[] = 'severity'; // 'severity'
			$t_columns[] = 'reproducibility'; // 'reproducibility'
			$t_columns[] = 'version'; // 'version'
			$t_columns[] = 'projection'; // 'projection'
			$t_columns[] = 'category'; // 'category'
			$t_columns[] = 'date_submitted'; // 'date_submitted'
			$t_columns[] = 'eta'; // 'eta'
			$t_columns[] = 'os'; // 'os'
			$t_columns[] = 'os_build'; // 'os_version'
			$t_columns[] = 'platform'; // 'platform'
			$t_columns[] = 'view_state'; // 'view_status'
			$t_columns[] = 'last_updated'; // 'last_update'
			$t_columns[] = 'summary'; // 'summary'
			$t_columns[] = 'status'; // 'status'
			$t_columns[] = 'resolution'; // 'resolution'
			$t_columns[] = 'fixed_in_version'; // 'fixed_in_version';

			if ( OFF == config_get( 'enable_relationship' ) ) {
				$t_columns[] = 'duplicate_id'; // 'duplicate_id'
			}
		} else {
			$t_columns[] = 'selection';

			if ( $p_columns_target == COLUMNS_TARGET_VIEW_PAGE ) {
				$t_columns[] = 'edit';
			}

#			$t_columns[] = 'priority';
			$t_columns[] = 'id';
			$t_columns[] = 'Risk #';
			$t_columns[] = 'custom_Special Priority';
			$t_columns[] = 'custom_Marketing #';

			$t_enable_sponsorship = config_get( 'enable_sponsorship' );
			if ( ON == $t_enable_sponsorship ) {
				$t_columns[] = 'sponsorship_total';
			}

			$t_columns[] = 'bugnotes_count';

			$t_show_attachments = config_get( 'show_attachment_indicator' );
			if ( ON == $t_show_attachments ) {
				$t_columns[] = 'attachment';
			}

			$t_columns[] = 'category';
#			$t_columns[] = 'severity';
			$t_columns[] = 'status';
			$t_columns[] = 'last_updated';
			$t_columns[] = 'summary';
		}

		return $t_columns;
	}

	#modified print_view_bug_sort_link to fix the problem.
  	function print_view_bug_sort_link( $p_string, $p_sort_field, $p_sort, $p_dir, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE )
    {
        if ( $p_columns_target == COLUMNS_TARGET_PRINT_PAGE ) {
			if ( $p_sort_field == $p_sort ) {
				# We toggle between ASC and DESC if the user clicks the same sort order
				if ( 'ASC' == $p_dir ) {
					$p_dir = 'DESC';
				} else {
					$p_dir = 'ASC';
				}
			} else {                        # Otherwise always start with ASCending
				$t_dir = 'ASC';
			}

			echo '<a href="view_all_set.php?sort='.urlencode($p_sort_field).'&amp;dir='.$p_dir.'&amp;type=2&amp;print=1">'.$p_string.'</a>';
		} else if ( $p_columns_target == COLUMNS_TARGET_VIEW_PAGE ) {
			if ( $p_sort_field == $p_sort ) {
				# we toggle between ASC and DESC if the user clicks the same sort order
				if ( 'ASC' == $p_dir ) {
					$p_dir = 'DESC';
				} else {
					$p_dir = 'ASC';
				}
			} else {                        # Otherwise always start with ASCending
				$t_dir = 'ASC';
			}

			echo '<a href="view_all_set.php?sort='.urlencode($p_sort_field).'&amp;dir='.$p_dir.'&amp;type=2">'.$p_string.'</a>';
		} else {
			echo $p_string;
		}
	}

Relationships

duplicate of 0012680 closeddregad Custom field name with paranthesis leads to db error message when sorting "view issues" 
duplicate of 0012404 closeddregad custom field sort issue on view issues page 
related to 0003767 closedgrangeway Enumeration Custum fields with html-special chars get unselected on bug-update 
related to 0005859 closeddaryn "Sort by" can't handle more than one custom field in combination 

Activities

giallu

giallu

2007-08-30 03:36

reporter   ~0015550

Could you please resubmit your fix as a patch? more info for creating a proper patch here:

http://www.mantisbt.org/wiki/doku.php/mantisbt:howto_submit_patches

ntbone

ntbone

2007-08-30 12:23

reporter   ~0015557

I will do so as soon as possible.

Hauptmann

Hauptmann

2010-05-06 11:47

reporter   ~0025429

We get these SQL-errors when sorting for custom fields containing "special" characters:

  • Fixed in Version (>=)
  • Effort [d]
    As soon as we removed the "(>=)" or the "[d]" the sorting worked.
squarebox

squarebox

2010-05-06 20:52

reporter   ~0025433

Hauptmann also posted the same fix for 0005859
so i wonder if these two bugs are actually related.

daryn

daryn

2010-12-22 15:48

reporter   ~0027678

See the patches attached to 0005859 as they appear to fix this problem for me.