[BUGFIX] Ensure unix like paths for temp files 07/36507/2
authorNicole Cordes <typo3@cordes.co>
Sat, 31 Jan 2015 11:18:32 +0000 (12:18 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 31 Jan 2015 14:12:15 +0000 (15:12 +0100)
Using tempnam() on Windows systems returns paths containing backslashes.
As other paths inside the core are already transformed to paths using
forward slashes some string comparisons fail. This patch ensures correct
transforming of slashes after the usage of tempnam().

Releases: master, 6.2
Resolves: #64682
Change-Id: Ic85e06d9ed32c9f668efd5bb74b9bc14df367e1b
Reviewed-on: http://review.typo3.org/36507
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php

index 70c0ad8..50be2ef 100755 (executable)
@@ -4017,7 +4017,7 @@ Connection: close
        static public function tempnam($filePrefix, $fileSuffix = '') {
                $temporaryPath = PATH_site . 'typo3temp/';
                if ($fileSuffix === '') {
-                       $tempFileName = tempnam($temporaryPath, $filePrefix);
+                       $tempFileName = static::fixWindowsFilePath(tempnam($temporaryPath, $filePrefix));
                } else {
                        do {
                                $tempFileName = $temporaryPath . $filePrefix . mt_rand(1, PHP_INT_MAX) . $fileSuffix;
index 15a2272..137df69 100644 (file)
@@ -2132,6 +2132,35 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        }
 
        //////////////////////////////////////
+       // Tests concerning tempnam
+       //////////////////////////////////////
+
+       /**
+        * @test
+        */
+       public function tempnamReturnsPathStartingWithGivenPrefix() {
+               $filePath = Utility\GeneralUtility::tempnam('foo');
+               $fileName = basename($filePath);
+               $this->assertStringStartsWith('foo', $fileName);
+       }
+
+       /**
+        * @test
+        */
+       public function tempnamReturnsPathWithoutBackslashes() {
+               $filePath = Utility\GeneralUtility::tempnam('foo');
+               $this->assertNotContains('\\', $filePath);
+       }
+
+       /**
+        * @test
+        */
+       public function tempnamReturnsAbsolutePathInsideDocumentRoot() {
+               $filePath = Utility\GeneralUtility::tempnam('foo');
+               $this->assertStringStartsWith(PATH_site, $filePath);
+       }
+
+       //////////////////////////////////////
        // Tests concerning addSlashesOnArray
        //////////////////////////////////////
        /**