[BUGFIX] Ensure unix like paths for temp files 93/36493/4
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:11:27 +0000 (15:11 +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/36493
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Tested-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Mateusz WojtuƂa <matw88@gmail.com>
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 04d2812..cbdf974 100755 (executable)
@@ -3982,7 +3982,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 3b1a925..6b55f52 100644 (file)
@@ -2116,6 +2116,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
        //////////////////////////////////////
        /**