Commit abd13f0c authored by Andreas Lappe's avatar Andreas Lappe Committed by Wouter Wolters
Browse files

[BUGFIX] Make filter respect hidden directories

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/31890


Reviewed-by: default avatarMarkus Klein <klein.t3@reelworx.at>
Tested-by: default avatarMarkus Klein <klein.t3@reelworx.at>
Reviewed-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
parent fd1c8cd9
......@@ -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;
......@@ -70,4 +70,4 @@ class FileNameFilter {
return self::$showHiddenFilesAndFolders = (bool)$showHiddenFilesAndFolders;
}
}
}
\ No newline at end of file
<?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(DriverInterface::class);
$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(DriverInterface::class);
FileNameFilter::setShowHiddenFilesAndFolders(TRUE);
$this->assertSame(
FileNameFilter::filterHiddenFilesAndFolders(
$itemName, $itemIdentifier, '', array(), $driverMock
),
$expected
);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment