[BUGFIX] Make filter respect hidden directories 89/31889/4
authorAndreas Lappe <info@zimmer7.com>
Mon, 28 Jul 2014 22:06:48 +0000 (00:06 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 12 Dec 2014 19:49:47 +0000 (20:49 +0100)
Make the filename filter respect files in hidden directories,
so that files inside those are not indexed by default.

Resolves: #60649
Releases: master, 6.2
Change-Id: Ia0306cb8996964c4998d9d69b526c3d6a8da2ace
Reviewed-on: http://review.typo3.org/31889
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/core/Classes/Resource/Filter/FileNameFilter.php
typo3/sysext/core/Tests/Unit/Resource/Filter/FileNameFilterTest.php [new file with mode: 0644]

index a86e888..07f8250 100644 (file)
@@ -42,7 +42,7 @@ class FileNameFilter {
         */
        static public function filterHiddenFilesAndFolders($itemName, $itemIdentifier, $parentIdentifier, array $additionalInformation, \TYPO3\CMS\Core\Resource\Driver\DriverInterface $driverInstance) {
                // Only apply the filter if you want to hide the hidden files
-               if (self::$showHiddenFilesAndFolders === FALSE && $itemName[0] === '.') {
+               if (self::$showHiddenFilesAndFolders === FALSE && strpos($itemIdentifier, '/.') !== FALSE) {
                        return -1;
                } else {
                        return TRUE;
diff --git a/typo3/sysext/core/Tests/Unit/Resource/Filter/FileNameFilterTest.php b/typo3/sysext/core/Tests/Unit/Resource/Filter/FileNameFilterTest.php
new file mode 100644 (file)
index 0000000..7c3abed
--- /dev/null
@@ -0,0 +1,89 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Resource\Filter;
+
+/**
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Core\Resource\Driver\DriverInterface;
+use TYPO3\CMS\Core\Resource\Filter\FileNameFilter;
+
+/**
+ * Testcase for the filename filter of the TYPO3 VFS
+ */
+class FileNameFilterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+
+       /**
+        * Return combinations of files and paths to test against.
+        *
+        * @return array
+        */
+       public function getItemsAndPathsWithoutHiddenFilesAndFolders_dataProvider() {
+               return array(
+                       array('file', '/file', TRUE),
+                       array('.htaccess', '/.htaccess', -1),
+                       array('applypatch-msg.sample', '/.git/applypatch-msg.sample', -1),
+                       array('applypatch-msg.sample', '/user_upload/.git/applypatch-msg.sample', -1),
+               );
+       }
+
+       /**
+        * Return combinations of files and paths to test against.
+        *
+        * @return array
+        */
+       public function getItemsAndPathsWithHiddenFilesAndFolders_dataProvider() {
+               return array(
+                       array('file', '/file', TRUE),
+                       array('.htaccess', '/.htaccess', TRUE),
+                       array('applypatch-msg.sample', '/.git/applypatch-msg.sample', TRUE),
+                       array('applypatch-msg.sample', '/user_upload/.git/applypatch-msg.sample', TRUE),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider getItemsAndPathsWithoutHiddenFilesAndFolders_dataProvider
+        * @param string $itemName
+        * @param string $itemIdentifier
+        * @param bool|int $expected
+        */
+       public function filterHiddenFilesAndFoldersFiltersHiddenFilesAndFolders($itemName, $itemIdentifier, $expected) {
+               /** @var DriverInterface|\PHPUnit_Framework_MockObject_MockObject $driverMock */
+               $driverMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\DriverInterface');
+               $this->assertSame(
+                       $expected,
+                       FileNameFilter::filterHiddenFilesAndFolders(
+                               $itemName, $itemIdentifier, '', array(), $driverMock
+                       )
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider getItemsAndPathsWithHiddenFilesAndFolders_dataProvider
+        * @param string $itemName
+        * @param string $itemIdentifier
+        * @param bool|int $expected
+        */
+       public function filterHiddenFilesAndFoldersAllowsHiddenFilesAndFolders($itemName, $itemIdentifier, $expected) {
+               /** @var DriverInterface|\PHPUnit_Framework_MockObject_MockObject $driverMock */
+               $driverMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\DriverInterface');
+               FileNameFilter::setShowHiddenFilesAndFolders(TRUE);
+               $this->assertSame(
+                       FileNameFilter::filterHiddenFilesAndFolders(
+                               $itemName, $itemIdentifier, '', array(), $driverMock
+                       ),
+                       $expected
+               );
+       }
+}