[BUGFIX] baseUrlWrap can handle url without scheme again 06/48606/2
authorWouter Wolters <typo3@wouterwolters.nl>
Wed, 15 Jun 2016 08:39:51 +0000 (10:39 +0200)
committerFrank Naegler <frank.naegler@typo3.org>
Mon, 20 Jun 2016 07:51:58 +0000 (09:51 +0200)
Since #54091 the baseUrlWrap method can't handle urls
without a scheme anymore. Fix this by checking the scheme
exists or not.

Resolves: #76403
Releases: master,7.6
Change-Id: I2a28519ef1fbafd245ececaa4b6cbedc716c0fa5
Reviewed-on: https://review.typo3.org/48606
Reviewed-by: Susanne Moog <typo3@susannemoog.de>
Tested-by: Susanne Moog <typo3@susannemoog.de>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
typo3/sysext/frontend/Tests/Unit/Controller/TypoScriptFrontendControllerTest.php

index f9b7df5..350bda5 100644 (file)
@@ -4105,7 +4105,7 @@ class TypoScriptFrontendController
     {
         if ($this->baseUrl) {
             $urlParts = parse_url($url);
-            if ($urlParts['scheme'] === '' && $url[0] !== '/') {
+            if (empty($urlParts['scheme']) && $url[0] !== '/') {
                 $url = $this->baseUrl . $url;
             }
         }
index 51200c2..4b5ffb6 100644 (file)
@@ -255,4 +255,47 @@ class TypoScriptFrontendControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCas
         $_SERVER['SCRIPT_NAME'] = $scriptName;
         $this->assertEquals($expectedResult, $this->subject->domainNameMatchesCurrentRequest($domainRecord));
     }
+
+    /**
+     * @return array
+     */
+    public function baseUrlWrapHandlesDifferentUrlsDataProvider()
+    {
+        return [
+            'without base url' => [
+                '',
+                'fileadmin/user_uploads/image.jpg',
+                'fileadmin/user_uploads/image.jpg'
+            ],
+            'with base url' => [
+                'http://www.google.com/',
+                'fileadmin/user_uploads/image.jpg',
+                'http://www.google.com/fileadmin/user_uploads/image.jpg'
+            ],
+            'without base url but with url prepended with a forward slash' => [
+                '',
+                '/fileadmin/user_uploads/image.jpg',
+                '/fileadmin/user_uploads/image.jpg',
+            ],
+            'with base url but with url prepended with a forward slash' => [
+                'http://www.google.com/',
+                '/fileadmin/user_uploads/image.jpg',
+                '/fileadmin/user_uploads/image.jpg',
+            ],
+        ];
+    }
+
+    /**
+     * @dataProvider baseUrlWrapHandlesDifferentUrlsDataProvider
+     * @test
+     * @param string $baseUrl
+     * @param string $url
+     * @param string $expected
+     */
+    public function baseUrlWrapHandlesDifferentUrls($baseUrl, $url, $expected)
+    {
+        $this->subject->baseUrl = $baseUrl;
+        $this->assertSame($expected, $this->subject->baseUrlWrap($url));
+    }
+
 }