From 173b99e6addd97d37fb64c028bd69c9ad27847be Mon Sep 17 00:00:00 2001
From: Wouter Wolters <typo3@wouterwolters.nl>
Date: Wed, 15 Jun 2016 10:39:51 +0200
Subject: [PATCH] [BUGFIX] baseUrlWrap can handle url without scheme again

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/48583
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Tested-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Susanne Moog <typo3@susannemoog.de>
Tested-by: Susanne Moog <typo3@susannemoog.de>
---
 .../TypoScriptFrontendController.php          |  2 +-
 .../TypoScriptFrontendControllerTest.php      | 43 +++++++++++++++++++
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
index 81f52cc9bb42..fefcde5c6bf6 100644
--- a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
+++ b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
@@ -3870,7 +3870,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;
             }
         }
diff --git a/typo3/sysext/frontend/Tests/Unit/Controller/TypoScriptFrontendControllerTest.php b/typo3/sysext/frontend/Tests/Unit/Controller/TypoScriptFrontendControllerTest.php
index ff0e06a21e68..32baa22d0bb3 100644
--- a/typo3/sysext/frontend/Tests/Unit/Controller/TypoScriptFrontendControllerTest.php
+++ b/typo3/sysext/frontend/Tests/Unit/Controller/TypoScriptFrontendControllerTest.php
@@ -254,4 +254,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));
+    }
+
 }
-- 
GitLab