View Issue Details

IDProjectCategoryView StatusLast Update
0017325mantisbtcode cleanuppublic2019-01-11 06:39
Reportergrangeway Assigned Todregad  
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
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

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 06:16

dregad


Details Diff
helper_array_transpose() only handles bidimentional arrays

Fixes 0017325
Affected Issues
0017325
mod - core/helper_api.php Diff File

MantisBT: master-1.3.x fb35359b

2016-09-01 06:16

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
Affected Issues
0017325
mod - core/helper_api.php Diff File

MantisBT: master-1.3.x dd39f53b

2016-09-03 10:55

vboctor


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

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