[BUGFIX] typolink: Ensure explode() is using string 44/52344/8
authorNicole Cordes <typo3@cordes.co>
Mon, 3 Apr 2017 17:33:52 +0000 (19:33 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Mon, 3 Apr 2017 22:22:27 +0000 (00:22 +0200)
Link to home page with section and enabled realurl ends up in uncaught
exception because the new PageLinkBuilder is a PHP7 strict
class, and thus, throws errors when explode() is used with null
as parameter.

Releases: master
Resolves: #80664
Change-Id: I206c4846ca9b381cca85d99ba3cc846dadbb266c
Reviewed-on: https://review.typo3.org/52344
Reviewed-by: Claus Due <claus@phpmind.net>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/frontend/Classes/Typolink/PageLinkBuilder.php
typo3/sysext/frontend/Tests/Functional/ContentObject/ContentObjectRendererTest.php

index 9dc30fc..49194fb 100644 (file)
@@ -224,7 +224,7 @@ class PageLinkBuilder extends AbstractTypolinkBuilder
 
             if (!trim($currentQueryParams)) {
                 list(, $URLparams) = explode('?', $url);
-                list($URLparams) = explode('#', $URLparams);
+                list($URLparams) = explode('#', (string)$URLparams);
                 parse_str($URLparams . $LD['orig_type'], $URLparamsArray);
                 // Type nums must match as well as page ids
                 if ((int)$URLparamsArray['type'] === (int)$tsfe->type) {
index cd13ccc..295bb3c 100644 (file)
@@ -470,6 +470,61 @@ class ContentObjectRendererTest extends \TYPO3\TestingFramework\Core\Functional\
     }
 
     /**
+     * @test
+     */
+    public function typolinkReturnsCorrectLinkForSectionToHomePageWithUrlRewriting()
+    {
+        $pageRepositoryMockObject = $this->getMockBuilder(PageRepository::class)
+            ->setMethods(['getPage'])
+            ->getMock();
+        $pageRepositoryMockObject->expects($this->any())->method('getPage')->willReturn([
+            'uid' => 1,
+            'title' => 'Page title',
+        ]);
+
+        $templateServiceMockObject = $this->getMockBuilder(TemplateService::class)
+            ->setMethods(['linkData'])
+            ->getMock();
+        $templateServiceMockObject->setup = [
+            'lib.' => [
+                'parseFunc.' => $this->getLibParseFunc(),
+            ],
+        ];
+        $templateServiceMockObject->expects($this->once())->method('linkData')->willReturn([
+            'url' => '/index.php?id=1',
+            'target' => '',
+            'type' => '',
+            'orig_type' => '',
+            'no_cache' => '',
+            'linkVars' => '',
+            'sectionIndex' => '',
+            'totalURL' => '/',
+        ]);
+
+        $typoScriptFrontendController = GeneralUtility::makeInstance(
+            TypoScriptFrontendController::class,
+            null,
+            1,
+            0
+        );
+        $typoScriptFrontendController->config = [
+            'config' => [],
+            'mainScript' => 'index.php',
+        ];
+        $typoScriptFrontendController->sys_page = $pageRepositoryMockObject;
+        $typoScriptFrontendController->tmpl = $templateServiceMockObject;
+        $GLOBALS['TSFE'] = $typoScriptFrontendController;
+
+        $configuration = [
+            'parameter' => 1,
+            'section' => 'content',
+        ];
+
+        $subject = GeneralUtility::makeInstance(ContentObjectRenderer::class);
+        $this->assertEquals('<a href="#content">Page title</a>', $subject->typoLink('', $configuration));
+    }
+
+    /**
      * @return array
      */
     protected function getLibParseTarget()