From 20abf1939e138704cfe9fe06db663cc7593b5c34 Mon Sep 17 00:00:00 2001 From: Fynn Gutic <66220444+Fynn93@users.noreply.github.com> Date: Sun, 5 Sep 2021 18:13:25 +0200 Subject: [PATCH 1/8] fix spelling --- .env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.example b/.env.example index d9bc415..bed4d8f 100644 --- a/.env.example +++ b/.env.example @@ -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 From 026f88ff85bfaaabc8646cb5c81025139d3f8d87 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Sat, 18 Sep 2021 14:07:40 +0200 Subject: [PATCH 2/8] add HIDE_DOT_FILES to .env.example so users can easily disable this function. enabled by default as per https://github.com/DirectoryLister/DirectoryLister/discussions/701#discussioncomment-1335516 --- .env.example | 1 + 1 file changed, 1 insertion(+) diff --git a/.env.example b/.env.example index bed4d8f..b66bd4c 100644 --- a/.env.example +++ b/.env.example @@ -8,6 +8,7 @@ APP_LANGUAGE=en DISPLAY_READMES=true READMES_FIRST=false ZIP_DOWNLOADS=true +HIDE_DOT_FILES=true GOOGLE_ANALYTICS_ID=false From 774da418fdf38fae7dbaa40e4a12fdf160abf653 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Sat, 18 Sep 2021 14:13:22 +0200 Subject: [PATCH 3/8] add hide_dot_files attribute to app/config/app.php and fix a little typo --- app/config/app.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/config/app.php b/app/config/app.php index 1d411ff..56a8942 100644 --- a/app/config/app.php +++ b/app/config/app.php @@ -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), ]; From 2bd44229d5d9d8896b537e05f8f53d896bb83cce Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Sat, 18 Sep 2021 14:39:20 +0200 Subject: [PATCH 4/8] add hide_dot_files to Finder init add 'set Finder.hideDotFiles to config.hide_dot_files' to Finder init in app/src/Factories/FinderFactory.php. Before, it was TRUE by Finder-default. --- app/src/Factories/FinderFactory.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/Factories/FinderFactory.php b/app/src/Factories/FinderFactory.php index 5a9956d..27c4482 100644 --- a/app/src/Factories/FinderFactory.php +++ b/app/src/Factories/FinderFactory.php @@ -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 { From fa8af46a17f223d0d26f4d7859308a08562ee077 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Sat, 18 Sep 2021 14:40:05 +0200 Subject: [PATCH 5/8] Add .env and .env.example to app_files --- app/config/container.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/config/container.php b/app/config/container.php index 6cfdee3..b1026b5 100644 --- a/app/config/container.php +++ b/app/config/container.php @@ -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 { From 224fbf0f72c641b93ec79e8c01ce8a2b0298993f Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Sat, 18 Sep 2021 23:57:21 +0200 Subject: [PATCH 6/8] update app.php "coding standards" error 1/1 always add a dot to the end of a sentence! --- app/config/app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/config/app.php b/app/config/app.php index 56a8942..ae594a8 100644 --- a/app/config/app.php +++ b/app/config/app.php @@ -162,7 +162,7 @@ return [ /** * Whether or not to hide dot files/directories from the listing. - * Like '.env' or '.ssh/' + * Like '.env' or '.ssh/'. * * Default value: true */ From c8144cc4d7c3e7613a91b68236e9918e34b83219 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Sun, 19 Sep 2021 00:38:16 +0200 Subject: [PATCH 7/8] update HiddenFilesTest.php with new app files '.env' and '.env.example' need to be included in app files, as dot files are now displayable. The tests did not expect that. I guess they were built with 'hidden files are hidden anyways' in mind. max line length is 88 (80 + 10% tolerance) chars I assume --- tests/HiddenFilesTest.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/HiddenFilesTest.php b/tests/HiddenFilesTest.php index fc2bdd5..2e687dc 100644 --- a/tests/HiddenFilesTest.php +++ b/tests/HiddenFilesTest.php @@ -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', ], ], ]; From 38336cafa8c28b55f8624e1f3d5d347facd7329d Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Sun, 19 Sep 2021 01:01:14 +0200 Subject: [PATCH 8/8] add tests for dot_files to FinderFactoryTest.php add test_dot_files_are_returned(): full directory content including .dot_file and .dot_dir add public function test_dot_directory_contents_are_returned(): subdirectory .dot_dir content containing .dot_file --- tests/Factories/FinderFactoryTest.php | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/Factories/FinderFactoryTest.php b/tests/Factories/FinderFactoryTest.php index 16c3129..891a695 100644 --- a/tests/Factories/FinderFactoryTest.php +++ b/tests/Factories/FinderFactoryTest.php @@ -97,6 +97,46 @@ 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', + '.dot_file', + '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');