From f83873bf1c95f5a371955e969fdb0f0bcc0fcc46 Mon Sep 17 00:00:00 2001 From: Tomita Militaru <militarutomita@gmail.com> Date: Thu, 28 Nov 2013 12:31:25 +0200 Subject: [PATCH] [TASK] Cleanup GeneralUtility::rmFromList Simplifies the method. Avoids using array as intermediate. Work directly with the string value instead. Resolves: #53677 Releases: 6.2 Change-Id: I1abcd606a2699e959be1816c88cb147dbf557141 Reviewed-on: https://review.typo3.org/25723 Reviewed-by: Stefan Neufeind Tested-by: Stefan Neufeind Reviewed-by: Oliver Klee Reviewed-by: Markus Klein Tested-by: Markus Klein --- .../core/Classes/Utility/GeneralUtility.php | 15 ++++++++------- .../Tests/Unit/Utility/GeneralUtilityTest.php | 4 +++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php index 0ee56bcd9067..52ecaa385c1f 100644 --- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php +++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php @@ -715,13 +715,14 @@ class GeneralUtility { * @return string New comma-separated list of items */ static public function rmFromList($element, $list) { - $items = explode(',', $list); - foreach ($items as $k => $v) { - if ($v == $element) { - unset($items[$k]); - } - } - return implode(',', $items); + return trim( + str_replace( + ',' . $element . ',', + ',', + ',' . $list . ',' + ), + ',' + ); } /** diff --git a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php index 58be263091e7..1995c278ed23 100644 --- a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php +++ b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php @@ -684,7 +684,9 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { 'Element at end of list' => array('one,two,removeme', 'one,two'), 'One item list' => array('removeme', ''), 'Element not contained in list' => array('one,two,three', 'one,two,three'), - 'Empty list' => array('', '') + 'Empty list' => array('', ''), + 'List with leading comma is trimmed afterwards' => array(',one,two,removeme', 'one,two'), + 'List with trailing comma is trimmed afterwards' => array('one,two,removeme,', 'one,two'), ); } -- GitLab