Bug #19601

t3lib_div::trimExplode limit parameter leads to wrong result with non-empty requirement

Added by Oliver Hader about 11 years ago. Updated over 9 years ago.

Status:
Closed
Priority:
Should have
Assignee:
Category:
-
Target version:
-
Start date:
2008-11-12
Due date:
% Done:

0%

TYPO3 Version:
4.3
PHP Version:
5.2
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

First, look at the function that was extended during TYPO3 4.3 development:
trimExplode($delim, $string, $onlyNonEmptyValues = false, $limit = 0)

Imagine a list like this:
$string = 'aa,,bb';

1) trimExplode(',', $string, false, 2) returns array('aa', ',bb') -> fine
2) trimExplode(',', $string, true, 2) returns array('aa', ',bb') -> false since it should be array('aa', 'bb') and the empty value removed <b>before</b>

(issue imported from #M9779)

9779.diff View (695 Bytes) Administrator Admin, 2009-03-02 12:35

9779_tests.diff View (1.36 KB) Administrator Admin, 2009-03-02 12:36

0009779_followup.patch View (3.29 KB) Administrator Admin, 2009-10-20 12:25


Related issues

Related to TYPO3 Core - Bug #20068: simplify and speed up t3lib_div::trimExplode() Closed 2009-02-21
Related to TYPO3 Core - Feature #17299: Enable/integrate conditions in Page TSconfig Closed 2007-05-11

History

#1 Updated by Franz Holzinger almost 11 years ago

I also think that a final reset($array) is missing. This had been done in former versions of TYPO3.

#2 Updated by Ingo Renner over 10 years ago

The behavior of the $limit parameter is correct according to http://php.net/explode

#3 Updated by Ingo Renner over 10 years ago

... currently the either the documentation for the $limit parameter is wrong or the implementation for the documented behavior

#4 Updated by Ingo Renner over 10 years ago

the documentation of the parameter however fits the one of http://www.php.net/manual/en/function.array-slice.php

#5 Updated by Ingo Renner over 10 years ago

the attached patch makes the method behave like advertised in the description

#6 Updated by Oliver Hader over 10 years ago

Looks good... +1 on reading

#7 Updated by Ingo Renner over 10 years ago

committed to trunk (4.3)

#8 Updated by Oliver Hader about 10 years ago

Reopened... the behaviour will be reworked...

#9 Updated by Oliver Hader about 10 years ago

Added a follow-up patch, that come back to the behaviour of the original explode() function in PHP:

Example:

t3lib_div::trimExplode(",", " a , b , c , d, ,e, f , , ", true, 3);
will be array("a", "b", "c,d,e,f")

#10 Updated by Oliver Hader about 10 years ago

Using the RegExp "t3lib_div::trimExplode\([^)]+,\s*[2-9]\s*\)" to find parts where this is used in the core I got the following:
t3lib_extMgm:544: $itemDetails = t3lib_div::trimExplode(';', $itemPart, false, 5);

#11 Updated by Oliver Hader about 10 years ago

Committed the follow-up patch to SVN Trunk (rev. 6180)

Also available in: Atom PDF