Project

General

Profile

Actions

Feature #53677

closed

GeneralUtility::rmFromList : allow to call GeneralUtility::trimExplode

Added by Clément MICHELET over 10 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Could have
Assignee:
-
Category:
-
Target version:
-
Start date:
Due date:
% Done:

100%

Estimated time:
PHP Version:
Tags:
Complexity:
no-brainer
Sprint Focus:

Description

If a list contains space between comma and value, rmFromList doesn't unset element.

Example :
  • "1,2, 3,4"
  • If we want to delete "3" entry, we have to pass " 3" instead of "3"

Current code is :

static public function rmFromList($element, $list) {
    $items = explode(',', $list);
    foreach ($items as $k => $v) {
        if ($v == $element) {
            unset($items[$k]);
        }
    }
    return implode(',', $items);
}

To avoid breaking changes, it can be introduced a new argument which enable trim.
Improved code :

static public function rmFromList($element, $list, $trimElements = false) {
    if(!$trimElements){
        $items = explode(',', $list);
    }
    else{
        $items = self::trimExplode(",", $list);
    }

    foreach ($items as $k => $v) {
        if ($v == $element) {
            unset($items[$k]);
        }
    }
    return implode(',', $items);
}


Files

53577-GeneralUtilityTest.patch (1.75 KB) 53577-GeneralUtilityTest.patch Clément MICHELET, 2013-11-29 16:47
53577-GeneralUtilityTest.patch (1.82 KB) 53577-GeneralUtilityTest.patch Replace wrong patch files which have missing commas Clément MICHELET, 2013-11-29 18:01

Related issues 2 (0 open2 closed)

Related to TYPO3 Core - Bug #55104: GeneralUtility::inList must delete white spaceRejected2014-01-17

Actions
Related to TYPO3 Core - Bug #65123: GeneralUtility::rmFromList() regression bugClosedMarkus Klein2015-02-17

Actions
Actions

Also available in: Atom PDF