diff --git a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
index 81f52cc9bb4270881911ae8cfb188f0dad8c8502..fefcde5c6bf6d75e0768efe100805069e86d78ed 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 ff0e06a21e68f85f7460291f769f0a922fef6466..32baa22d0bb3b814b168251c900ee9219a9e3f22 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));
+    }
+
 }