View Issue Details

IDProjectCategoryView StatusLast Update
0013935mantisbtfilterspublic2014-12-22 08:22
Reporteratrol Assigned Todregad  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Product Version1.2.9 
Target Version1.2.9Fixed in Version1.2.9 
Summary0013935: Version based filtering not possible
Description

When trying to filter a version you get APPLICATION ERROR # 1601 or other strange results (depends on browser)

Steps To Reproduce
  1. Go to www.mantisbt.orgs/bugs
  2. Choose "View Issues"
  3. Try to filter on any version field
TagsNo tags attached.
Attached Files
filter_error.PNG (100,412 bytes)   
filter_error.PNG (100,412 bytes)   
0001-Fix-13935-Version-based-filtering-not-possible.patch (1,285 bytes)   
From a155e0fc659197e1c7bb8a244c45f461c4261100 Mon Sep 17 00:00:00 2001
From: Damien Regad <damien.regad@merckgroup.com>
Date: Wed, 22 Feb 2012 00:48:32 +0100
Subject: [PATCH] Fix #13935: Version-based filtering not possible

Commit a68398245663d25229800638b6965ffe6e7ab0d3 for bug #13096
introduced a regression in version-based filtering due to not properly
dealing with selected version parameter when passed as an array.
---
 core/print_api.php |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/core/print_api.php b/core/print_api.php
index f8966e1..59e6d12 100644
--- a/core/print_api.php
+++ b/core/print_api.php
@@ -764,9 +764,12 @@ function print_version_option_list( $p_version = '', $p_project_id = null, $p_re
 		null );
 	}
 
-	# Ensure the current version (if specified) is included in the list
-	if( !empty( $p_version ) ) {
-		$versions[] = version_cache_row( version_get_id( $p_version, $c_project_id ) );
+	# Ensure the selected version (if specified) is included in the list
+	# Note: Filter API specifies selected versions as an array
+	if( !is_array( $p_version ) ) {
+		if( !empty( $p_version ) ) {
+			$versions[] = version_cache_row( version_get_id( $p_version, $c_project_id ) );
+		}
 	}
 
 	if( $p_leading_blank ) {
-- 
1.7.5.4

Relationships

related to 0013096 closeddregad Spurious Target Version Behaviour. 
related to 0013775 confirmed print_version_option_list() causes error when called for all projects 
related to 0015721 closedgrangeway Functionality to consider porting to master-2.0.x 
related to 0013937 closeddregad Versions and Categories from existing filter not preselected when editing it 
related to 0013938 closeddregad Error when editing issue having version not existing in current project 

Activities

atrol

atrol

2012-02-21 11:06

developer   ~0031277

Last edited: 2012-02-21 11:09

Seems to be introduced by fix of 0013096
https://github.com/mantisbt/mantisbt/commit/a68398245663d25229800638b6965ffe6e7ab0d3
https://github.com/mantisbt/mantisbt/commit/0ffb20f8807fc600750690e201ebf5fb325e7bfc

atrol

atrol

2012-02-21 11:13

developer   ~0031278

Reminder sent to: dregad

please have a look at this issue

dregad

dregad

2012-02-21 12:52

developer   ~0031279

It's strange. I can't reproduce this on my dev box, but I can on this tracker:

  • with Firefox I get the same behavior shown on atrol's attached screenshot
  • with IE8, I get the "Error on page" icon at bottom with following message <pre>
    Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET CLR 1.1.4322; .NET4.0C; .NET4.0E)
Timestamp: Tue, 21 Feb 2012 17:03:33 UTC

Message: Unknown runtime error
Line: 1
Char: 671
Code: 0
URI: http://www.mantisbt.org/bugs/javascript/min/dynamic_filters.js
</pre>

So my commit is apparently causing an issue in the script's execution.

I'm not sure where to go from here - I don't know much about javascript to begin with, and as I cant reproduce it locally that makes it hard to investigate directly on mantisbt.org due to the compacted javascripts.

Are you able to reproduce locally?

jreese

jreese

2012-02-21 13:39

reporter   ~0031280

Starting from a fresh cache, the version filters seem to work correctly until you "reset filter". For the record, I just updated this tracker to latest origin/master-1.2.x, and the error is still occurring.

atrol

atrol

2012-02-21 16:10

developer   ~0031282

using
if( !is_blank( $p_version ) ) {
instead of
if( !empty( $p_version ) ) {
in function print_version_option_list seems to fix the problem, but I am not sure if this is the intended behaviour.

I am no PHP developer and after reading section "Return Values" at
http://php.net/manual/en/function.empty.php
I know a little bit more why I don't really like untyped languages.
0 as an integer returns FALSE, ....

Seems there are some more issues around version selection which have been introduced since version 1.2.8
P1 with version V1
P2 with version V2
Move an issue from P1 to P2, click "Edit" button
You get APPLICATION ERROR # 1601

atrol

atrol

2012-02-21 17:03

developer   ~0031283

The following code seems to fix also the new issue mentioned at 0013935:0031282
But a real PHP developer should have a deep look at this code
Especially !== false is quite strange for a non PHP developer and != false seems to do also the job

<pre>
if( !is_blank( $p_version ) ) {
$t_version_id = version_get_id( $p_version, $c_project_id );
if ( $t_version_id !== false ) {
$versions[] = version_cache_row( $t_version_id );
}
}
</pre>

Another approach could be to call version_cache_row with false as second parameter and check the return value

At the moment I prefer to discard the commit which introduces this issues, push out 1.2.9 and target the clean solution to 1.2.10

dregad

dregad

2012-02-21 17:33

developer   ~0031284

I think I get it. The filter API (in view issues page) calls print_version_option_list() with an array of values, but the code does not properly handle that.

Testing this, I noticed another flaw with the version filters: the current code (including 1.2.8) is not able to select the values from the list when updating an existing filter. In other words, assume you have a saved filter on Product Version 2; if you use that filter then click on Product Version to modify the criteria, nothing is selected (should be 2).

dregad

dregad

2012-02-21 19:05

developer   ~0031285

atrol, can you please test the attached fix (as I can't reproduce the behavior locally)

See also related 0013937 for the issue with preselection of versions from existing filter as described in 0013935:0031284

dregad

dregad

2012-02-21 19:32

developer   ~0031286

I created 0013938 to track the issue reported in 0013935:0031282

atrol

atrol

2012-02-22 04:36

developer   ~0031289

atrol, can you please test the attached fix (as I can't reproduce the behavior locally)

The patch fixes this issue (not the related 0013937 and 0013938)

dregad

dregad

2012-02-22 05:51

developer   ~0031292

OK, thanks for confirming. I'll push the commit later today.

I know this does not address the other 2 - I have fixes lined up for these too, which I will push also but did not want to anticipate on that to avoid conflicting patches on the same section of code in case you did not confirm the fix.

Thanks for testing !

grangeway

grangeway

2013-04-05 17:57

reporter   ~0036369

Marking as 'acknowledged' not resolved/closed to track that change gets ported to master-2.0.x branch

Related Changesets

MantisBT: master 57e20055

2012-02-21 10:48

dregad


Details Diff
Fix 0013935: Version-based filtering not possible

Commit a68398245663d25229800638b6965ffe6e7ab0d3 for bug 0013096
introduced a regression in version-based filtering due to not properly
dealing with selected version parameter when passed as an array.
Affected Issues
0013096, 0013935
mod - core/print_api.php Diff File

MantisBT: master-1.2.x 84c6fe6a

2012-02-21 10:48

dregad


Details Diff
Fix 0013935: Version-based filtering not possible

Commit a68398245663d25229800638b6965ffe6e7ab0d3 for bug 0013096
introduced a regression in version-based filtering due to not properly
dealing with selected version parameter when passed as an array.
Affected Issues
0013096, 0013935
mod - core/print_api.php Diff File