Merge branch 'ciscam-master'

This commit is contained in:
Chris Kankiewicz
2021-09-18 23:31:31 -07:00
7 changed files with 57 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
# Here you can control Directory Lister configuration through environment
# varaibles. See the configuration documentation for additional information:
# variables. See the configuration documentation for additional information:
# https://docs.directorylister.com/configuration
APP_DEBUG=false
@@ -8,6 +8,7 @@ APP_LANGUAGE=en
DISPLAY_READMES=true
READMES_FIRST=false
ZIP_DOWNLOADS=true
HIDE_DOT_FILES=true
GOOGLE_ANALYTICS_ID=false

View File

@@ -122,7 +122,7 @@ return [
],
/**
* Whether or not to hide application files/directories form the listing.
* Whether or not to hide application files/directories from the listing.
*
* Default value: true
*/
@@ -159,4 +159,12 @@ return [
* Default value: 1000000000
*/
'max_hash_size' => DI\env('MAX_HASH_SIZE', 1000000000),
/**
* Whether or not to hide dot files/directories from the listing.
* Like '.env' or '.ssh/'.
*
* Default value: true
*/
'hide_dot_files' => DI\env('HIDE_DOT_FILES', true),
];

View File

@@ -17,7 +17,7 @@ return [
'views_path' => DI\string('{app_path}/views'),
/** Array of application files (to be hidden) */
'app_files' => ['app', 'index.php', '.hidden'],
'app_files' => ['app', 'index.php', '.hidden', '.env', '.env.example'],
/** Array of application middlewares */
'middlewares' => function (): array {

View File

@@ -42,6 +42,7 @@ class FinderFactory
{
$finder = Finder::create()->followLinks();
$finder->ignoreVCS($this->config->get('hide_vcs_files'));
$finder->ignoreDotFiles($this->config->get('hide_dot_files'));
if ($this->hiddenFiles->isNotEmpty()) {
$finder->filter(function (SplFileInfo $file): bool {

View File

@@ -97,6 +97,45 @@ class FinderFactoryTest extends TestCase
], $this->getFilesArray($finder));
}
public function test_dot_files_are_returned(): void
{
$this->container->set('hidden_files', []);
$this->container->set('hide_dot_files', false);
$finder = (new FinderFactory(
$this->container,
$this->config,
HiddenFiles::fromConfig($this->config)
))();
$finder->in($this->filePath('subdir'))->depth(0);
$this->assertInstanceOf(Finder::class, $finder);
$this->assertEquals([
'.dot_dir',
'alpha.scss',
'bravo.js',
'charlie.bash',
'delta.html',
'echo.yaml',
], $this->getFilesArray($finder));
}
public function test_dot_directory_contents_are_returned(): void
{
$this->container->set('hidden_files', []);
$this->container->set('hide_dot_files', false);
$finder = (new FinderFactory(
$this->container,
$this->config,
HiddenFiles::fromConfig($this->config)
))();
$finder->in($this->filePath('subdir/.dot_dir'))->depth(0);
$this->assertInstanceOf(Finder::class, $finder);
$this->assertEquals(['.dot_file'], $this->getFilesArray($finder));
}
public function test_it_throws_a_runtime_exception_with_an_invalid_sort_order(): void
{
$this->container->set('sort_order', 'invalid');

View File

@@ -50,11 +50,14 @@ class HiddenFilesTest extends TestCase
[], $this->filePath('.hidden'), false, ['alpha', 'bravo'],
],
'App files' => [
[], 'NOT_A_REAL_FILE', true, ['app', 'index.php', '.hidden'],
[], 'NOT_A_REAL_FILE', true, [
'app', 'index.php', '.hidden', '.env', '.env.example',
],
],
'All' => [
['foo', 'alpha'], $this->filePath('.hidden'), true, [
'foo', 'alpha', 'bravo', 'app', 'index.php', '.hidden',
'foo', 'alpha', 'bravo', 'app', 'index.php', '.hidden', '.env',
'.env.example',
],
],
];

View File