76747[WIP][BUGFIX] Improve type safety of GU explode methods
Commit message
Review
-
Code review CR 0
-
Verified V 0
Issues 1
Files 5
- typo3/sysext/core/Classes/Utility/GeneralUtility.php2+3 −4
- typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php+4 −0
- typo3/sysext/extbase/Classes/Property/TypeConverter/ArrayConverter.php+1 −1
- typo3/sysext/frontend/Classes/DataProcessing/SplitProcessor.php+1 −0
- typo3/sysext/impexp/Classes/Command/ImportCommand.php+2 −0
Review log 2431
Show 56 earlier messages
-
Oliver Klee uploaded patch set 1 11/20/22, 16:13
-
Oliver Klee marked it work in progress 11/20/22, 16:14
-
core-ci voted on patch set 1 V +1 11/20/22, 16:21 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/34012
-
Oliver Klee uploaded patch set 2
V +111/20/22, 16:25 -
Oliver Klee marked it ready for review 11/20/22, 16:26
-
Oliver Klee uploaded patch set 3 11/20/22, 16:29
-
core-ci voted on patch set 2 V +1 11/20/22, 16:35 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/34013
-
core-ci voted on patch set 3 V +1 11/20/22, 16:38 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/34014
-
Stefan Bürk commented on patch set 3 11/20/22, 17:36
-
Oliver Klee commented on patch set 3 11/20/22, 17:44
TransportFactory.php:90ReplyIn line 79, trimExplode is called with the third argument $removeEmpty set to true. That means that there will be no empty string in the array. If we leave the check in, PHPStan will rightfully complain that this check will always be false. -
Stefan Bürk commented on patch set 3 11/20/22, 17:45
TransportFactory.php:90ReplyAck -
Nikita Hovratov voted on patch set 3 CR +1 11/22/22, 21:00
-
Nikita Hovratov voted on patch set 3 V +1 11/22/22, 21:39
-
Stefan Bürk voted on patch set 3 CR -1 11/22/22, 22:47
-
Stefan Bürk commented on patch set 3 11/22/22, 22:59
GeneralUtility.php:861This `(int)` cast here is definitly wrong. Result of "implode" *may* be a string with multiple values separated by `$delimiter`. For example: ```php $result = intExplode(',', '1,2,3,4,5', false, 3); // expected: [1,2,'3,4,5'] // with int cast: [1,2,3] ``` This is a absoluty change in behaviour. Granted, should be better documeted for the $limit argument. Also the return type annotation is wrong anyway. If behaviour should be changed, thenn there is no need to "implode" the "last elements" .. simply use the first one. Or shift the split (slicing) one position further and remove the last element handling. But this would be "breaking". We use this a lot in custom project extension, expecting exactly that behaviour. So maybe other developers are expecting the same. Thus not doable in v12, and even more not as backport. Sadly, there is no test for this case. But can be easily added. So, here should be rethought about what should be really done. ``` diff --git a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php index 205edf855a..c0adda0b6c 100644 --- a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php +++ b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php @@ -744,23 +744,33 @@ class GeneralUtilityTest extends UnitTestCase 'convertStringToInteger' => [ '1,foo,2', false, + 'limit' => 0, [1, 0, 2], ], 'zerosAreKept' => [ '0,1, 0, 2,0', false, + 'limit' => 0, [0, 1, 0, 2, 0], ], 'emptyValuesAreKept' => [ '0,1,, 0, 2,,0', false, + 'limit' => 0, [0, 1, 0, 0, 2, 0, 0], ], 'emptyValuesAreRemoved' => [ '0,1,, 0, 2,,0', true, + 'limit' => 0, [0=>0, 1=>1, 3=>0, 4=>2, 6=>0], // note does not renumber keys! ], + 'convertStringToIntegerKeepingOverLimit' => [ + '1,foo,2,3,4,5', + false, + 'limit' => 3, + [1, 0, '2,3,4,5'], + ], ]; } @@ -768,9 +778,9 @@ class GeneralUtilityTest extends UnitTestCase * @test * @dataProvider intExplodeDataProvider */ - public function intExplodeReturnsExplodedArray(string $input, bool $removeEmpty, array $expected): void + public function intExplodeReturnsExplodedArray(string $input, bool $removeEmpty, int $limit, array $expected): void { - self::assertSame($expected, GeneralUtility::intExplode(',', $input, $removeEmpty)); + self::assertSame($expected, GeneralUtility::intExplode(',', $input, $removeEmpty, $limit)); } ////////////////////////////////// ``` -
Nikita Hovratov voted on patch set 3 V 0 CR 0 11/23/22, 16:34
-
Oliver Klee commented on patch set 3 CR -1 11/23/22, 16:42
Maybe I'll split this up into two changes. And we definitely should talk about the intExplode. -
Oliver Klee marked it work in progress 03/14/23, 15:16
-
Oliver Klee uploaded patch set 4
CR -1V +103/14/23, 15:17 -
core-ci voted on patch set 4 V -1 03/14/23, 15:59 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38935
-
Oliver Klee uploaded patch set 5
V -103/27/23, 11:38 -
Oliver Klee wrote 04/05/23, 12:02
Topic set to phpstan -
Oliver Klee uploaded patch set 6 07/18/23, 15:41
-
core-ci voted on patch set 6 V -1 07/18/23, 15:54 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/44269
-
Oliver Klee rebased onto patch set 7
V -107/18/23, 22:01 -
core-ci voted on patch set 7 V -1 07/18/23, 22:15 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/44284
-
Oliver Klee uploaded patch set 8
V -111/25/23, 13:38 -
core-ci voted on patch set 8 V +1 11/25/23, 13:44 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/49923
-
Oliver Klee commented on patch set 8 11/25/23, 14:14
This change is ready for review.GeneralUtility.php:861ReplyClosing this comment as now the change does not include the corresponding change in behavior anymore. -
Oliver Klee marked it work in progress 11/25/23, 14:14
-
Oliver Klee abandoned the change 08/25/24, 10:10
TransportFactory.php:90