diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php index 18c55a086404bb826e7c1da629d71283683885ff..46350c9942dec567b075edf15d445bfc68a9b93f 100644 --- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php +++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php @@ -1483,7 +1483,7 @@ class GeneralUtility $identifier = md5($string . $NSprefix . ($reportDocTag ? '1' : '0')); // Look up in first level cache if (empty($firstLevelCache[$identifier])) { - $firstLevelCache[$identifier] = self::xml2arrayProcess(trim($string), $NSprefix, $reportDocTag); + $firstLevelCache[$identifier] = self::xml2arrayProcess($string, $NSprefix, $reportDocTag); $runtimeCache->set('generalUtilityXml2Array', $firstLevelCache); } return $firstLevelCache[$identifier]; @@ -1499,8 +1499,9 @@ class GeneralUtility * @return mixed If the parsing had errors, a string with the error message is returned. Otherwise an array with the content. * @see array2xml() */ - protected static function xml2arrayProcess($string, $NSprefix = '', $reportDocTag = false) + public static function xml2arrayProcess($string, $NSprefix = '', $reportDocTag = false) { + $string = trim($string); // Disables the functionality to allow external entities to be loaded when parsing the XML, must be kept $previousValueOfEntityLoader = null; if (PHP_MAJOR_VERSION < 8) { diff --git a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php index 74e7fdfee25f3ef37979ff41fcc0cac50ffc99d0..2ac79985db781d83ed25f421e564b61e066d0633 100644 --- a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php +++ b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php @@ -4085,10 +4085,24 @@ class GeneralUtilityTest extends UnitTestCase </phparray>', $output); } + /** + * @test + */ + public function xml2arrayUsesCache(): void + { + $cacheManagerProphecy = $this->prophesize(CacheManager::class); + $cacheProphecy = $this->prophesize(FrontendInterface::class); + $cacheManagerProphecy->getCache('runtime')->willReturn($cacheProphecy->reveal()); + $cacheProphecy->get('generalUtilityXml2Array')->shouldBeCalled()->willReturn(false); + $cacheProphecy->set('generalUtilityXml2Array', Argument::cetera())->shouldBeCalled(); + GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal()); + GeneralUtility::xml2array('<?xml version="1.0" encoding="utf-8" standalone="yes"?>', 'T3:'); + } + /** * @return string[][] */ - public function xml2arrayHandlesWhitespacesDataProvider(): array + public function xml2arrayProcessHandlesWhitespacesDataProvider(): array { $headerVariants = [ 'utf-8' => '<?xml version="1.0" encoding="utf-8" standalone="yes"?>', @@ -4143,17 +4157,10 @@ class GeneralUtilityTest extends UnitTestCase /** * @test - * @dataProvider xml2arrayHandlesWhitespacesDataProvider - * @param string $input + * @dataProvider xml2arrayProcessHandlesWhitespacesDataProvider */ - public function xml2arrayHandlesWhitespaces(string $input) + public function xml2arrayProcessHandlesWhitespaces(string $input): void { - $cacheManagerProphecy = $this->prophesize(CacheManager::class); - $cacheProphecy = $this->prophesize(FrontendInterface::class); - $cacheManagerProphecy->getCache('runtime')->willReturn($cacheProphecy->reveal()); - $cacheProphecy->get('generalUtilityXml2Array')->shouldBeCalled()->willReturn(false); - $cacheProphecy->set('generalUtilityXml2Array', Argument::cetera())->shouldBeCalled(); - GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal()); $expected = [ 'data' => [ 'settings.persistenceIdentifier' => [ @@ -4161,13 +4168,13 @@ class GeneralUtilityTest extends UnitTestCase ] ], ]; - self::assertSame($expected, GeneralUtility::xml2array($input)); + self::assertSame($expected, GeneralUtility::xml2arrayProcess($input)); } /** * @return string[][] */ - public function xml2arrayHandlesTagNamespacesDataProvider(): array + public function xml2arrayProcessHandlesTagNamespacesDataProvider(): array { return [ 'inputWithNameSpaceOnRootLevel' => [ @@ -4205,17 +4212,10 @@ class GeneralUtilityTest extends UnitTestCase /** * @test - * @dataProvider xml2arrayHandlesTagNamespacesDataProvider - * @param string $input + * @dataProvider xml2arrayProcessHandlesTagNamespacesDataProvider */ - public function xml2arrayHandlesTagNamespaces(string $input) + public function xml2arrayProcessHandlesTagNamespaces(string $input): void { - $cacheManagerProphecy = $this->prophesize(CacheManager::class); - $cacheProphecy = $this->prophesize(FrontendInterface::class); - $cacheManagerProphecy->getCache('runtime')->willReturn($cacheProphecy->reveal()); - $cacheProphecy->get('generalUtilityXml2Array')->shouldBeCalled()->willReturn(false); - $cacheProphecy->set('generalUtilityXml2Array', Argument::cetera())->shouldBeCalled(); - GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal()); $expected = [ 'data' => [ 'settings.persistenceIdentifier' => [ @@ -4223,13 +4223,13 @@ class GeneralUtilityTest extends UnitTestCase ] ], ]; - self::assertSame($expected, GeneralUtility::xml2array($input, 'T3:')); + self::assertSame($expected, GeneralUtility::xml2arrayProcess($input, 'T3:')); } /** * @return array[] */ - public function xml2arrayHandlesDocumentTagDataProvider(): array + public function xml2arrayProcessHandlesDocumentTagDataProvider(): array { return [ 'input' => [ @@ -4270,18 +4270,10 @@ class GeneralUtilityTest extends UnitTestCase /** * @test - * @dataProvider xml2arrayHandlesDocumentTagDataProvider - * @param string $input - * @param string $docTag + * @dataProvider xml2arrayProcessHandlesDocumentTagDataProvider */ - public function xml2arrayHandlesDocumentTag(string $input, string $docTag) + public function xml2arrayProcessHandlesDocumentTag(string $input, string $docTag): void { - $cacheManagerProphecy = $this->prophesize(CacheManager::class); - $cacheProphecy = $this->prophesize(FrontendInterface::class); - $cacheManagerProphecy->getCache('runtime')->willReturn($cacheProphecy->reveal()); - $cacheProphecy->get('generalUtilityXml2Array')->shouldBeCalled()->willReturn(false); - $cacheProphecy->set('generalUtilityXml2Array', Argument::cetera())->shouldBeCalled(); - GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal()); $expected = [ 'data' => [ 'settings.persistenceIdentifier' => [ @@ -4290,13 +4282,13 @@ class GeneralUtilityTest extends UnitTestCase ], '_DOCUMENT_TAG' => $docTag ]; - self::assertSame($expected, GeneralUtility::xml2array($input, '', true)); + self::assertSame($expected, GeneralUtility::xml2arrayProcess($input, '', true)); } /** * @return array[] */ - public function xml2ArrayHandlesBigXmlContentDataProvider(): array + public function xml2ArrayProcessHandlesBigXmlContentDataProvider(): array { return [ '1mb' => [ @@ -4326,18 +4318,12 @@ class GeneralUtilityTest extends UnitTestCase /** * @test - * @dataProvider xml2ArrayHandlesBigXmlContentDataProvider + * @dataProvider xml2ArrayProcessHandlesBigXmlContentDataProvider * @param string $input * @param string $testValue */ - public function xml2ArrayHandlesBigXmlContent(string $input, string $testValue) + public function xml2ArrayProcessHandlesBigXmlContent(string $input, string $testValue): void { - $cacheManagerProphecy = $this->prophesize(CacheManager::class); - $cacheProphecy = $this->prophesize(FrontendInterface::class); - $cacheManagerProphecy->getCache('runtime')->willReturn($cacheProphecy->reveal()); - $cacheProphecy->get('generalUtilityXml2Array')->shouldBeCalled()->willReturn(false); - $cacheProphecy->set('generalUtilityXml2Array', Argument::cetera())->shouldBeCalled(); - GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal()); $expected = [ 'data' => [ 'settings.persistenceIdentifier' => [ @@ -4345,7 +4331,7 @@ class GeneralUtilityTest extends UnitTestCase ] ], ]; - self::assertSame($expected, GeneralUtility::xml2array($input)); + self::assertSame($expected, GeneralUtility::xml2arrayProcess($input)); } /** @@ -4381,7 +4367,7 @@ class GeneralUtilityTest extends UnitTestCase /** * @return array[] */ - public function xml2ArrayHandlesAttributeTypesDataProvider() + public function xml2ArrayProcessHandlesAttributeTypesDataProvider(): array { $prefix = '<?xml version="1.0" encoding="utf-8" standalone="yes"?><T3FlexForms><field index="index">'; $suffix = '</field></T3FlexForms>'; @@ -4455,19 +4441,13 @@ class GeneralUtilityTest extends UnitTestCase /** * @test - * @dataProvider xml2ArrayHandlesAttributeTypesDataProvider + * @dataProvider xml2ArrayProcessHandlesAttributeTypesDataProvider * @param string $input * @param $expected */ - public function xml2ArrayHandlesAttributeTypes(string $input, $expected) + public function xml2ArrayProcessHandlesAttributeTypes(string $input, $expected): void { - $cacheManagerProphecy = $this->prophesize(CacheManager::class); - $cacheProphecy = $this->prophesize(FrontendInterface::class); - $cacheManagerProphecy->getCache('runtime')->willReturn($cacheProphecy->reveal()); - $cacheProphecy->get('generalUtilityXml2Array')->shouldBeCalled()->willReturn(false); - $cacheProphecy->set('generalUtilityXml2Array', Argument::cetera())->shouldBeCalled(); - GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal()); - $result = GeneralUtility::xml2array($input); + $result = GeneralUtility::xml2arrayProcess($input); self::assertSame($expected, $result['index']['vDEF']); }