[BUGFIX] Fix basename-fetch in basenameDuringBootstrap 44/56944/4
authorStefan Neufeind <typo3.neufeind@speedpartner.de>
Sat, 12 May 2018 18:48:08 +0000 (20:48 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 13 May 2018 09:50:51 +0000 (11:50 +0200)
Also add tests for dirnameDuringBootstrap and basenameDuringBootstrap.

Resolves: #84988
Related: #74806
Releases: master
Change-Id: I6544435f6c79425e7c008670cc5dd4df355b28c8
Reviewed-on: https://review.typo3.org/56944
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Andreas Wolf <andreas.wolf@typo3.org>
Tested-by: Andreas Wolf <andreas.wolf@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/Utility/PathUtility.php
typo3/sysext/core/Tests/Unit/Utility/PathUtilityTest.php

index ec846d6..d58d7ba 100644 (file)
@@ -289,7 +289,7 @@ class PathUtility
      */
     public static function basenameDuringBootstrap($path): string
     {
-        return preg_replace('#([^\\\\/]+)$#', '$1', $path);
+        return preg_replace('#.*[/\\\\]([^\\\\/]+)$#', '$1', $path);
     }
 
     /*********************
index 389efcc..b95d7db 100644 (file)
@@ -370,4 +370,82 @@ class PathUtilityTest extends UnitTestCase
             PathUtility::getCanonicalPath($inputName)
         );
     }
+
+    /**
+     * Data provider for dirnameDuringBootstrapCorrectlyFetchesParent
+     *
+     * @return array
+     */
+    public function dirnameDuringBootstrapCorrectlyFetchesParentDataProvider()
+    {
+        return [
+            'relative path' => [
+                'abc/def/ghi',
+                'abc/def'
+            ],
+            'absolute path 1' => [
+                '/var/www/html/index.php',
+                '/var/www/html'
+            ],
+            'absolute path 2' => [
+                '/var/www/html/typo3/index.php',
+                '/var/www/html/typo3'
+            ],
+            'windows path' => [
+                'C:\\inetpub\\index.php',
+                'C:\\inetpub'
+            ],
+        ];
+    }
+
+    /**
+     * @test
+     * @dataProvider dirnameDuringBootstrapCorrectlyFetchesParentDataProvider
+     */
+    public function dirnameDuringBootstrapCorrectlyFetchesParent($inputPath, $expectedResult)
+    {
+        $this->assertEquals(
+            $expectedResult,
+            PathUtility::dirnameDuringBootstrap($inputPath)
+        );
+    }
+
+    /**
+     * Data provider for basenameDuringBootstrapCorrectlyFetchesBasename
+     *
+     * @return array
+     */
+    public function basenameDuringBootstrapCorrectlyFetchesBasenameDataProvider()
+    {
+        return [
+            'relative path' => [
+                'abc/def/ghi',
+                'ghi'
+            ],
+            'absolute path 1' => [
+                '/var/www/html/index.php',
+                'index.php'
+            ],
+            'absolute path 2' => [
+                '/var/www/html/typo3/index.php',
+                'index.php'
+            ],
+            'windows path' => [
+                'C:\\inetpub\\index.php',
+                'index.php'
+            ],
+        ];
+    }
+
+    /**
+     * @test
+     * @dataProvider basenameDuringBootstrapCorrectlyFetchesBasenameDataProvider
+     */
+    public function basenameDuringBootstrapCorrectlyFetchesBasename($inputPath, $expectedResult)
+    {
+        $this->assertEquals(
+            $expectedResult,
+            PathUtility::basenameDuringBootstrap($inputPath)
+        );
+    }
 }