[BUGFIX] Fix behavior of revExplode if delimiter not found 24/27524/3
authorAlexander Stehlik <alexander.stehlik@googlemail.com>
Mon, 10 Feb 2014 12:51:48 +0000 (13:51 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 10 Feb 2014 20:41:11 +0000 (21:41 +0100)
If the given delimiter is not found in the given string
GeneralUtility::revExplode() will return an array with a single element
containing the unexploded string.

Resolves: #55838
Releases: 6.2
Change-Id: I1146552a625a8057be86b2745febf808638a290c
Reviewed-on: https://review.typo3.org/27524
Reviewed-by: Andreas Wolf
Tested-by: Andreas Wolf
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php

index 82fd86d..9e84404 100644 (file)
@@ -1484,7 +1484,11 @@ class GeneralUtility {
                // 2 is the (currently, as of 2014-02) most-used value for $count in the core, therefore we check it first
                if ($count === 2) {
                        $position = strrpos($string, $delimiter);
-                       return array(substr($string, 0, $position), substr($string, $position + 1));
+                       if ($position !== FALSE) {
+                               return array(substr($string, 0, $position), substr($string, $position + 1));
+                       } else {
+                               return array($string);
+                       }
                } elseif ($count <= 1) {
                        return array($string);
                } else {
index 9a935e6..10e3f75 100644 (file)
@@ -1375,6 +1375,26 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                3,
                                array('my', 'words', 'here')
                        ),
+                       'limit 0 should return unexploded string if no delimiter is contained' => array(
+                               'mywordshere',
+                               0,
+                               array('mywordshere')
+                       ),
+                       'limit 1 should return unexploded string if no delimiter is contained' => array(
+                               'mywordshere',
+                               1,
+                               array('mywordshere')
+                       ),
+                       'limit 2 should return unexploded string if no delimiter is contained' => array(
+                               'mywordshere',
+                               2,
+                               array('mywordshere')
+                       ),
+                       'limit 3 should return unexploded string if no delimiter is contained' => array(
+                               'mywordshere',
+                               3,
+                               array('mywordshere')
+                       ),
                );
        }