Commit 4a745b8d authored by Xavier Perseguers's avatar Xavier Perseguers Committed by Jigal van Hemert
Browse files

[BUGFIX] Invalid behaviour with GeneralUtility::trimExplode()

The subject's parts are wrongly trimmed although a limit is specified.
According to the PHP documentation, the values are trimmed for whitespace
in the end, not at the beginning.

Change-Id: Ifb4547b3349be2d31d5ce75b19db77eb6535d5ec
Resolves: #70864
Releases: master, 6.2
Reviewed-on: https://review.typo3.org/44178


Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez's avatarAndreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Jigal van Hemert's avatarJigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert's avatarJigal van Hemert <jigal.van.hemert@typo3.org>
parent 6792c33d
......@@ -1523,22 +1523,24 @@ class GeneralUtility
}
/**
* Explodes a string and trims all values for whitespace in the ends.
* Explodes a string and trims all values for whitespace in the end.
* If $onlyNonEmptyValues is set, then all blank ('') values are removed.
*
* @param string $delim Delimiter string to explode with
* @param string $string The string to explode
* @param bool $removeEmptyValues If set, all empty values will be removed in output
* @param int $limit If positive, the result will contain a maximum of
* @param int $limit If limit is set and positive, the returned array will contain a maximum of limit elements with
* the last element containing the rest of string. If the limit parameter is negative, all components
* except the last -limit are returned.
* @return array Exploded values
*/
public static function trimExplode($delim, $string, $removeEmptyValues = false, $limit = 0)
{
$result = array_map('trim', explode($delim, $string));
$result = explode($delim, $string);
if ($removeEmptyValues) {
$temp = array();
foreach ($result as $value) {
if ($value !== '') {
if (trim($value) !== '') {
$temp[] = $value;
}
}
......@@ -1550,6 +1552,7 @@ class GeneralUtility
} elseif ($limit < 0) {
$result = array_slice($result, 0, $limit);
}
$result = array_map('trim', $result);
return $result;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment