[BUGFIX] Correctly determine link type 06/46106/2
authorMarkus Klein <markus.klein@typo3.org>
Tue, 19 Jan 2016 19:56:43 +0000 (20:56 +0100)
committerMarkus Klein <markus.klein@typo3.org>
Wed, 20 Jan 2016 11:49:40 +0000 (12:49 +0100)
Due to a wrong condition transformation the detection of external links
without schema is broken.
Revert the condition to the correct logic again as it was in 6.2.

Related: #55626
Resolves: #72818
Releases: master, 7.6
Change-Id: I1cd716c4a689db1309d28d750e30987eeee3efff
Reviewed-on: https://review.typo3.org/46106
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/core/Classes/Database/SoftReferenceIndex.php
typo3/sysext/core/Classes/Html/RteHtmlParser.php
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php

index a33fb40..128d719 100644 (file)
@@ -595,7 +595,7 @@ class SoftReferenceIndex
         $containsSlash = strstr($rootFileDat, '/');
         $rFD_fI = pathinfo($rootFileDat);
         $fileExtension = strtolower($rFD_fI['extension']);
-        if ($fileExtension === 'php' || $fileExtension === 'html' || $fileExtension === 'htm' || trim($rootFileDat) && !$containsSlash && (@is_file(PATH_site . $rootFileDat))) {
+        if (!$containsSlash && trim($rootFileDat) && (@is_file(PATH_site . $rootFileDat) || $fileExtension === 'php' || $fileExtension === 'html' || $fileExtension === 'htm')) {
             $isLocalFile = 1;
         } elseif ($containsSlash) {
             // Adding this so realurl directories are linked right (non-existing).
index ed86bd7..2846d90 100644 (file)
@@ -701,7 +701,7 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser
                         list($rootFileDat) = explode('?', $link_param);
                         $rFD_fI = pathinfo($rootFileDat);
                         $fileExtension = strtolower($rFD_fI['extension']);
-                        if ($fileExtension === 'php' || $fileExtension === 'html' || $fileExtension === 'htm' || trim($rootFileDat) && !strstr($link_param, '/') && (@is_file((PATH_site . $rootFileDat)))) {
+                        if (strpos($link_param, '/') === false && trim($rootFileDat) && (@is_file(PATH_site . $rootFileDat) || $fileExtension === 'php' || $fileExtension === 'html' || $fileExtension === 'htm')) {
                             $href = $siteUrl . $link_param;
                         } elseif (
                             (
index 8eeb982..3efe51e 100644 (file)
@@ -6369,7 +6369,7 @@ class ContentObjectRenderer
             $containsSlash = strpos($rootFileDat, '/') !== false;
             $rFD_fI = pathinfo($rootFileDat);
             $fileExtension = strtolower($rFD_fI['extension']);
-            if ($fileExtension === 'php' || $fileExtension === 'html' || $fileExtension === 'htm' || trim($rootFileDat) && !$containsSlash && (@is_file((PATH_site . $rootFileDat)))) {
+            if (!$containsSlash && trim($rootFileDat) && (@is_file(PATH_site . $rootFileDat) || $fileExtension === 'php' || $fileExtension === 'html' || $fileExtension === 'htm')) {
                 $isLocalFile = 1;
             } elseif ($containsSlash) {
                 // Adding this so realurl directories are linked right (non-existing).
index f7ac169..8190c0c 100644 (file)
@@ -19,9 +19,11 @@ use TYPO3\CMS\Core\Charset\CharsetConverter;
 use TYPO3\CMS\Core\Core\ApplicationContext;
 use TYPO3\CMS\Core\Log\LogManager;
 use TYPO3\CMS\Core\TimeTracker\NullTimeTracker;
+use TYPO3\CMS\Core\TypoScript\TemplateService;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Frontend\ContentObject\AbstractContentObject;
 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
+use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
 use TYPO3\CMS\Frontend\Tests\Unit\ContentObject\Fixtures\PageRepositoryFixture;
 
 /**
@@ -45,12 +47,12 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     protected $subject = null;
 
     /**
-     * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
+     * @var \PHPUnit_Framework_MockObject_MockObject|TypoScriptFrontendController|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
      */
     protected $typoScriptFrontendControllerMock = null;
 
     /**
-     * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\TypoScript\TemplateService
+     * @var \PHPUnit_Framework_MockObject_MockObject|TemplateService
      */
     protected $templateServiceMock = null;
 
@@ -93,10 +95,10 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
         $this->createMockedLoggerAndLogManager();
 
-        $this->templateServiceMock = $this->getMock(\TYPO3\CMS\Core\TypoScript\TemplateService::class, array('getFileName', 'linkData'));
+        $this->templateServiceMock = $this->getMock(TemplateService::class, array('getFileName', 'linkData'));
         $pageRepositoryMock = $this->getMock(PageRepositoryFixture::class, array('getRawRecord'));
 
-        $this->typoScriptFrontendControllerMock = $this->getAccessibleMock(\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class, array('dummy'), array(), '', false);
+        $this->typoScriptFrontendControllerMock = $this->getAccessibleMock(TypoScriptFrontendController::class, array('dummy'), array(), '', false);
         $this->typoScriptFrontendControllerMock->tmpl = $this->templateServiceMock;
         $this->typoScriptFrontendControllerMock->config = array();
         $this->typoScriptFrontendControllerMock->page = array();
@@ -4161,6 +4163,63 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     /**
      * @return array
      */
+    public function detectLinkTypeFromLinkParameterDataProvider()
+    {
+        return [
+            'Domain only' => [
+                'example.com',
+                'url'
+            ],
+            'URL without a file' => [
+                'http://example.com',
+                'url'
+            ],
+            'URL with schema and a file' => [
+                'http://example.com/index.php',
+                'url'
+            ],
+            'URL with a file but without a schema' => [
+                'example.com/index.php',
+                'url'
+            ],
+            'file' => [
+                '/index.php',
+                'file'
+            ],
+        ];
+    }
+
+    /**
+     * @test
+     * @param string $linkParameter
+     * @param string $expectedResult
+     * @dataProvider detectLinkTypeFromLinkParameterDataProvider
+     */
+    public function detectLinkTypeFromLinkParameter($linkParameter, $expectedResult)
+    {
+        /** @var TemplateService|\PHPUnit_Framework_MockObject_MockObject $templateServiceObjectMock */
+        $templateServiceObjectMock = $this->getMock(TemplateService::class, array('dummy'));
+        $templateServiceObjectMock->setup = array(
+            'lib.' => array(
+                'parseFunc.' => $this->getLibParseFunc(),
+            ),
+        );
+        /** @var TypoScriptFrontendController|\PHPUnit_Framework_MockObject_MockObject $typoScriptFrontendControllerMockObject */
+        $typoScriptFrontendControllerMockObject = $this->getMock(TypoScriptFrontendController::class, array(), array(), '', false);
+        $typoScriptFrontendControllerMockObject->config = array(
+            'config' => array(),
+            'mainScript' => 'index.php',
+        );
+        $typoScriptFrontendControllerMockObject->tmpl = $templateServiceObjectMock;
+        $GLOBALS['TSFE'] = $typoScriptFrontendControllerMockObject;
+        $this->subject->_set('typoScriptFrontendController', $typoScriptFrontendControllerMockObject);
+
+        $this->assertEquals($expectedResult, $this->subject->_call('detectLinkTypeFromLinkParameter', $linkParameter));
+    }
+
+    /**
+     * @return array
+     */
     public function typolinkReturnsCorrectLinksForEmailsAndUrlsDataProvider()
     {
         return array(
@@ -4171,6 +4230,13 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                 ),
                 '<a href="http://typo3.org">TYPO3</a>',
             ),
+            'Link to url without schema' => array(
+                'TYPO3',
+                array(
+                    'parameter' => 'typo3.org',
+                ),
+                '<a href="http://typo3.org">TYPO3</a>',
+            ),
             'Link to url without link text' => array(
                 '',
                 array(
@@ -4244,13 +4310,13 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
      */
     public function typolinkReturnsCorrectLinksForEmailsAndUrls($linkText, $configuration, $expectedResult)
     {
-        $templateServiceObjectMock = $this->getMock(\TYPO3\CMS\Core\TypoScript\TemplateService::class, array('dummy'));
+        $templateServiceObjectMock = $this->getMock(TemplateService::class, array('dummy'));
         $templateServiceObjectMock->setup = array(
             'lib.' => array(
                 'parseFunc.' => $this->getLibParseFunc(),
             ),
         );
-        $typoScriptFrontendControllerMockObject = $this->getMock(\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class, array(), array(), '', false);
+        $typoScriptFrontendControllerMockObject = $this->getMock(TypoScriptFrontendController::class, array(), array(), '', false);
         $typoScriptFrontendControllerMockObject->config = array(
             'config' => array(),
             'mainScript' => 'index.php',
@@ -4468,13 +4534,13 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     {
         $pageRepositoryMockObject = $this->getMock(\TYPO3\CMS\Frontend\Page\PageRepository::class, array('getPage'));
         $pageRepositoryMockObject->expects($this->any())->method('getPage')->willReturn($pageArray);
-        $templateServiceObjectMock = $this->getMock(\TYPO3\CMS\Core\TypoScript\TemplateService::class, array('dummy'));
+        $templateServiceObjectMock = $this->getMock(TemplateService::class, array('dummy'));
         $templateServiceObjectMock->setup = array(
             'lib.' => array(
                 'parseFunc.' => $this->getLibParseFunc(),
             ),
         );
-        $typoScriptFrontendControllerMockObject = $this->getMock(\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class, array(), array(), '', false);
+        $typoScriptFrontendControllerMockObject = $this->getMock(TypoScriptFrontendController::class, array(), array(), '', false);
         $typoScriptFrontendControllerMockObject->config = array(
             'config' => array(),
             'mainScript' => 'index.php',
@@ -4543,13 +4609,13 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
      */
     public function typolinkReturnsCorrectLinksFiles($linkText, $configuration, $expectedResult)
     {
-        $templateServiceObjectMock = $this->getMock(\TYPO3\CMS\Core\TypoScript\TemplateService::class, array('dummy'));
+        $templateServiceObjectMock = $this->getMock(TemplateService::class, array('dummy'));
         $templateServiceObjectMock->setup = array(
             'lib.' => array(
                 'parseFunc.' => $this->getLibParseFunc(),
             ),
         );
-        $typoScriptFrontendControllerMockObject = $this->getMock(\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class, array(), array(), '', false);
+        $typoScriptFrontendControllerMockObject = $this->getMock(TypoScriptFrontendController::class, array(), array(), '', false);
         $typoScriptFrontendControllerMockObject->config = array(
             'config' => array(),
             'mainScript' => 'index.php',
@@ -4909,7 +4975,7 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     }
 
     /**
-     * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
+     * @return TypoScriptFrontendController
      */
     protected function getFrontendController() {
         return $GLOBALS['TSFE'];