View Issue Details

IDProjectCategoryView StatusLast Update
0017325mantisbtcode cleanuppublic2016-10-02 18:41
ReportergrangewayAssigned Todregad 
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionreopened 
Product Version1.2.16 
Target Version1.3.2Fixed in Version1.3.2 
Summary0017325: helper_array_transpose should always return an array
Description

function helper_array_transpose( $p_array ) {
if( !is_array( $p_array ) ) {
return $p_array;
}

The purpose of helper_array_transpose is documented to only take an input array (and indeed that is how we use it).

We should adjust the function to always return an array - if passed null, we should return an empty array(). This allows the result to be passed directly into a foreach loop for example

TagsNo tags attached.

Relationships

related to 0017322 closeddregad Warning in bug report when attachments are disabled 
related to 0015774 closeddregad Incorrect number of attached files 

Activities

dregad

dregad

2014-05-12 06:02

developer   ~0040258

While the proposed change is fine for the case of $p_array == NULL (which is how it's currently used in bug_report.php), what about when it's some other value (e.g. bug_file_add.php uses -1).

Also, how would you recommend handling the case of $p_array being a one-dimentional array ? Would you also return an empty array in this case ?

Anyway, that's an API change/improvement, which is independent from the original fix.

grangeway

grangeway

2014-05-12 06:42

reporter   ~0040261

we do if ( !is_array( $p ) return $p - so one-dimensional array isn't going to hit that code path.

I think in the case of one-dimensional array we currently return the original array?

Moving forwards, I'd like to simplify our input/output to functions to be stricter on the data types - hence my suggestion regarding array();

dregad

dregad

2016-09-05 04:45

developer   ~0053943

Last edited: 2016-09-05 04:47

View 3 revisions

Reopened following revert of MantisBT master-1.3.x eaa7286a

cproensa Sep 03 20:29
dregad, can you fix or revert you last commit eaa7286
Reporting a simple bug produces error:
/var/www/html/git/mantis13_cpm/core/error_api.php.error_handler:80
/var/www/html/git/mantis13_cpm/core/helper_api.php.trigger_error:94
/var/www/html/git/mantis13_cpm/core/helper_api.php.helper_array_transpose:94
/var/www/html/git/mantis13_cpm/core/file_api.php.file_process_posted_files_for_bug:67
/var/www/html/git/mantis13_cpm/bug_report.php.{main}:212

dregad

dregad

2016-09-17 12:52

developer   ~0054040

https://github.com/mantisbt/mantisbt/pull/890

Related Changesets

MantisBT: master-1.3.x eaa7286a

2016-09-01 10:16:15

dregad

Details Diff
helper_array_transpose() only handles bidimentional arrays

Fixes 0017325
mod - core/helper_api.php Diff File

MantisBT: master-1.3.x fb35359b

2016-09-01 10:16:15

dregad

Details Diff
helper_array_transpose() only handles bidimensional arrays

The function now triggers an error if the input array is not
bidimensional.

This fixes the issues introduced by earlier attempt (see commit
eaa7286a87ec5bce9320807c18df542427989f68, reverted in dd39f53bb009f1172a312c6ccbb8d4dbd6984e21).

The original did not properly handle associative arrays, and had faulty
logic causing the function to always fail for arrays. It also did not
detect some "non-square" arrays (i.e. with the 1st element as array and
the 2nd as scalar).

Fixes 0017325
mod - core/helper_api.php Diff File

MantisBT: master-1.3.x dd39f53b

2016-09-03 14:55:58

vboctor

Details Diff
Revert "helper_array_transpose() only handles bidimentional arrays"

This reverts commit eaa7286a87ec5bce9320807c18df542427989f68.
mod - core/helper_api.php Diff File

Issue History

Date Modified Username Field Change
2014-05-12 05:07 grangeway New Issue
2014-05-12 05:56 dregad Relationship added related to 0017322
2014-05-12 06:02 dregad Note Added: 0040258
2014-05-12 06:42 grangeway Note Added: 0040261
2014-11-25 12:37 vboctor Category feature => code cleanup
2016-09-01 10:42 dregad Changeset attached => MantisBT master-1.3.x eaa7286a
2016-09-01 10:42 dregad Assigned To => dregad
2016-09-01 10:42 dregad Status new => resolved
2016-09-01 10:42 dregad Resolution open => fixed
2016-09-01 10:42 dregad Fixed in Version => 1.3.2
2016-09-01 10:44 dregad Target Version => 1.3.2
2016-09-01 10:46 dregad Relationship added related to 0015774
2016-09-01 10:50 dregad Product Version => 1.2.16
2016-09-05 04:45 dregad Status resolved => assigned
2016-09-05 04:45 dregad Resolution fixed => reopened
2016-09-05 04:45 dregad Fixed in Version 1.3.2 =>
2016-09-05 04:45 dregad Note Added: 0053943
2016-09-05 04:45 dregad Note Edited: 0053943 View Revisions
2016-09-05 04:46 dregad Changeset attached => MantisBT master-1.3.x dd39f53b
2016-09-05 04:47 dregad Note Edited: 0053943 View Revisions
2016-09-17 12:52 dregad Note Added: 0054040
2016-09-29 05:02 dregad Changeset attached => MantisBT master-1.3.x fb35359b
2016-09-29 05:02 dregad Status assigned => resolved
2016-09-29 05:02 dregad Fixed in Version => 1.3.2
2016-10-02 18:41 vboctor Status resolved => closed