Bug #14310
closedfunction uniqueList got list ended with commata
0%
Description
If the function uniquiList in class.t3lib_div.php gets a list that ended with a commata a wrong SQL statement could be generated.
Added an if-statement, that checks, if the list ended with a commata, see added diff file.
(issue imported from #M350)
Files
Updated by Michael Cannon about 20 years ago
Why not not just preg_replace it out? I admit it always runs, but the control structure to seach for this has to do the samething.
Just a thought,
Michael
function uniqueList() {
$listArray = array();
$arg_list = func_get_args();
foreach ($arg_list as $in_list) {
if (!is_array($in_list)) {
// MLC, remove ending ,
$in_list = preg_replace( '#,$#', '', $in_list );
$in_list = explode(',',$in_list);
}
$listArray = array_merge($listArray,$in_list);
}
return implode(',',array_unique($listArray));
}
Updated by Karsten Hachmeister about 20 years ago
If you think preg_replace is the better choice, ok. With regular expression I always think it is more cpu intensive?!
Updated by Michael Cannon about 20 years ago
Well, both accomplish the same thing. I'd prefer to just run the command once, but as you said runtime should probably be the deciding factor. In the long run, I think whoever maintains this should make the decision.
Your substr method did help me solve something else though this morning. So thanks for the memory job on that function.
Updated by Karsten Hachmeister about 20 years ago
The time difference is not very much. I executed each variant 300000 times, the substr method took about 10,5 sek and the preg_replace method about 11,5 sek.
Updated by Michael Stucki about 20 years ago
Thanks guys. We already fixed this in CVS.
The bug was caused when I replaced t3lib_div::uniqueArray with the native PHP function array_unique().
Unfortunately, array_unique cannot remove empty values from an array. I fixed the problem by doing this before calling array_unique using t3lib_div::trimExplode(',',$values,1)
(the last parameter does the trick!)
See http://cvs.sourceforge.net/viewcvs.py/typo3/TYPO3core/t3lib/class.t3lib_div.php?r1=1.55&r2=1.56