Project

General

Profile

Actions

Bug #14310

closed

function uniqueList got list ended with commata

Added by Karsten Hachmeister almost 20 years ago. Updated almost 18 years ago.

Status:
Closed
Priority:
Should have
Category:
Frontend
Target version:
-
Start date:
2004-09-11
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
3.7-dev
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

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

0000350-class.t3lib_div_diff.php (163 Bytes) 0000350-class.t3lib_div_diff.php Administrator Admin, 2004-09-11 12:54
Actions #1

Updated by Michael Cannon almost 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));
}
Actions #2

Updated by Karsten Hachmeister almost 20 years ago

If you think preg_replace is the better choice, ok. With regular expression I always think it is more cpu intensive?!

Actions #3

Updated by Michael Cannon almost 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.

Actions #4

Updated by Karsten Hachmeister almost 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.

Actions #5

Updated by Michael Stucki almost 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

Actions

Also available in: Atom PDF