Fixed bug #14845: Bug: Filelist module reports "type" of files also for directories...
authorSusanne Moog <typo3@susannemoog.de>
Tue, 6 Jul 2010 19:57:50 +0000 (19:57 +0000)
committerSusanne Moog <typo3@susannemoog.de>
Tue, 6 Jul 2010 19:57:50 +0000 (19:57 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@8123 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_div.php
tests/t3lib/t3lib_divTest.php

index 3858a28..d527508 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-07-06  Susanne Moog  <typo3@susanne-moog.de>
+
+       * Fixed bug #14845: Bug: Filelist module reports "type" of files also for directories  (thanks to Caspar Stuebs and Andy Grunwald)
+
 2010-07-06  Christian Kuhn  <lolli@schwarzbu.ch>
 
        * Fixed bug #14885: No access to taskcenter (tasks) for non-admins (Thanks to Jigal van Hemert)
index dcf5c29..27a1304 100644 (file)
@@ -1134,15 +1134,16 @@ final class t3lib_div {
         */
        public static function split_fileref($fileref)  {
                $reg = array();
-               if (preg_match('/(.*\/)(.*)$/',$fileref,$reg)   )       {
+               if (preg_match('/(.*\/)(.*)$/', $fileref, $reg)) {
                        $info['path'] = $reg[1];
                        $info['file'] = $reg[2];
                } else {
                        $info['path'] = '';
                        $info['file'] = $fileref;
                }
-               $reg='';
-               if (    preg_match('/(.*)\.([^\.]*$)/',$info['file'],$reg)      )       {
+
+               $reg = '';
+               if (is_file($fileref) && preg_match('/(.*)\.([^\.]*$)/', $info['file'], $reg)) {
                        $info['filebody'] = $reg[1];
                        $info['fileext'] = strtolower($reg[2]);
                        $info['realFileext'] = $reg[2];
index 11f2ea7..97d615b 100644 (file)
@@ -1454,5 +1454,34 @@ class t3lib_divTest extends tx_phpunit_testcase {
                $this->assertTrue($mkdirResult);
                $this->assertTrue($directoryCreated);
        }
+
+       /**
+        * Checks if t3lib_div::split_fileref() return NO file extension if incomming $fileref is a folder
+        * This test avoid bug #0014845: Filelist module reports "type" of files also for directories
+        * This test assumes directory 'PATH_site'/typo3temp exists
+        *
+        * @test
+        * @see t3lib_div::split_fileref()
+        */
+       public function checkIfSplitFileRefReturnsFileTypeNotForFolders(){
+               $directoryName = uniqid('test_');
+               $directoryPath = PATH_site . 'typo3temp/';
+               $directory = $directoryPath . $directoryName;
+               mkdir($directory, octdec($GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask']));
+
+               $fileInfo = t3lib_div::split_fileref($directory);
+
+               $directoryCreated = is_dir($directory);
+               $this->assertTrue($directoryCreated);
+
+               $this->assertType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $fileInfo);
+               $this->assertEquals($directoryPath, $fileInfo['path']);
+               $this->assertEquals($directoryName, $fileInfo['file']);
+               $this->assertEquals($directoryName, $fileInfo['filebody']);
+               $this->assertEquals('', $fileInfo['fileext']);
+               $this->assertArrayNotHasKey('realFileext', $fileInfo);
+
+               rmdir($directory);
+       }
 }
 ?>
\ No newline at end of file