[BUGFIX] Cast $siteUrl to string
authorJochen Roth <jochen.roth@b13.com>
Fri, 23 Jul 2021 12:05:38 +0000 (14:05 +0200)
committerBenni Mack <benni@typo3.org>
Mon, 26 Jul 2021 16:58:30 +0000 (18:58 +0200)
In case substr returns false $siteUrl
is now casted to string and covered
by an additional unit test.

Resolves: #94624
Releases: master
Change-Id: Id778319104d107c329a2ee8f947571a87e3c401d
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/70059
Tested-by: Oliver Bartsch <bo@cedev.de>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Classes/Http/NormalizedParams.php
typo3/sysext/core/Tests/Unit/Http/NormalizedParamsTest.php

index bfb3646..fb236f2 100644 (file)
@@ -824,7 +824,7 @@ class NormalizedParams
     protected static function determineSiteUrl(string $requestDir, string $pathThisScript, string $pathSite): string
     {
         $pathThisScriptDir = substr(dirname($pathThisScript), strlen($pathSite)) . '/';
-        $siteUrl = substr($requestDir, 0, -strlen($pathThisScriptDir));
+        $siteUrl = (string)substr($requestDir, 0, -strlen($pathThisScriptDir));
 
         return rtrim($siteUrl, '/') . '/';
     }
index f05ecbf..b1baec3 100644 (file)
@@ -945,6 +945,19 @@ class NormalizedParamsTest extends UnitTestCase
         self::assertSame($expected, $serverRequestParameters->getSiteUrl());
     }
 
+    /**
+     * @test
+     */
+    public function getSiteUrlReturnsExpectedUrlForCliCommand()
+    {
+        $serverParams = [];
+        $pathThisScript = '/var/www/html/typo3temp/var/tests/acceptance/typo3/sysext/core/bin/typo3';
+        $pathSite = '/var/www/html/typo3temp/var/tests/acceptance/';
+        $expected = '/';
+        $serverRequestParameters = new NormalizedParams($serverParams, [], $pathThisScript, $pathSite);
+        self::assertSame($expected, $serverRequestParameters->getSiteUrl());
+    }
+
     /**
      * @return array[]
      */