From 207df6adda0892f7857eec75752c6d1dabc5c780 Mon Sep 17 00:00:00 2001 From: Christian Weiske <weiske@mogic.com> Date: Thu, 21 Apr 2016 09:09:57 +0200 Subject: [PATCH] [BUGFIX] Better positionName extraction in executePositionedStringInsertion Limit string explosion so that "LLL:EXT:" notation in $position does not get broken up. Resolves: #75830 Releases: master, 7.6 Change-Id: I13cc15562bd790040c3e45c9eb27ff029311c78f Reviewed-on: https://review.typo3.org/47832 Reviewed-by: Nicole Cordes <typo3@cordes.co> Tested-by: Nicole Cordes <typo3@cordes.co> Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl> Reviewed-by: Frans Saris <franssaris@gmail.com> Tested-by: Frans Saris <franssaris@gmail.com> --- .../Utility/ExtensionManagementUtility.php | 4 ++-- .../Utility/ExtensionManagementUtilityTest.php | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php b/typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php index 10d538d98648..47977da6a068 100644 --- a/typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php +++ b/typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php @@ -647,7 +647,7 @@ class ExtensionManagementUtility { $list = $newList = trim($list, ", \t\n\r\0\x0B"); - list($location, $positionName) = GeneralUtility::trimExplode(':', $insertionPosition); + list($location, $positionName) = GeneralUtility::trimExplode(':', $insertionPosition, false, 2); if ($location !== 'replace') { $insertionList = self::removeDuplicatesForInsertion($insertionList, $list); @@ -670,7 +670,7 @@ class ExtensionManagementUtility $positionName = str_replace(';;', ';[^;]*;', $positionName); } - $pattern = ('/(^|,\\s*)(' . $positionName . ')(;[^,$]+)?(,|$)/'); + $pattern = ('/(^|,\\s*)(' . preg_quote($positionName, '/') . ')(;[^,$]+)?(,|$)/'); switch ($location) { case 'after': $newList = preg_replace($pattern, '$1$2$3, ' . $insertionList . '$4', $list); diff --git a/typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php b/typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php index dc5f2074263a..6d2a38048e37 100644 --- a/typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php +++ b/typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php @@ -337,6 +337,22 @@ class ExtensionManagementUtilityTest extends UnitTestCase $this->assertEquals('fieldA, fieldB, fieldC;labelC, newA, newB, --palette--;;paletteC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']); } + /** + * Tests whether fields can be add to all TCA types and duplicate fields are considered. + * + * @test + * @see ExtensionManagementUtility::addToAllTCAtypes() + */ + public function canAddFieldsToAllTCATypesRespectsPalettes() + { + $table = $this->getUniqueId('tx_coretest_table'); + $GLOBALS['TCA'] = $this->generateTCAForTable($table); + $GLOBALS['TCA'][$table]['types']['typeD'] = ['showitem' => 'fieldY, --palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.palettes.standard;standard, fieldZ']; + ExtensionManagementUtility::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'after:--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.palettes.standard;standard'); + // Checking typeD: + $this->assertEquals('fieldY, --palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.palettes.standard;standard, newA, newB, fieldA, fieldZ', $GLOBALS['TCA'][$table]['types']['typeD']['showitem']); + } + /** * Tests whether fields can be add to a TCA type before existing ones * -- GitLab