diff --git a/packages/framework/src/Foundation/Kernel/Filesystem.php b/packages/framework/src/Foundation/Kernel/Filesystem.php index a207efa3d21..891e5e1b0c3 100644 --- a/packages/framework/src/Foundation/Kernel/Filesystem.php +++ b/packages/framework/src/Foundation/Kernel/Filesystem.php @@ -204,7 +204,11 @@ public function findFiles(string $directory, string|false $matchExtension = fals // Optionally match file extensions (case-insensitively) if ($matchExtension !== false) { - $finder->name('/\.' . preg_quote($matchExtension, '/') . '$/i'); + // Normalize input by removing a leading dot if present + $normalizedExtension = ltrim($matchExtension, '.'); + + // Use a case-insensitive regex to match file extensions + $finder->name('/\.' . preg_quote($normalizedExtension, '/') . '$/i'); } // Collect relative paths diff --git a/packages/framework/tests/Unit/FilesystemFindFilesTest.php b/packages/framework/tests/Unit/FilesystemFindFilesTest.php index 35eee65066a..c535b61d037 100644 --- a/packages/framework/tests/Unit/FilesystemFindFilesTest.php +++ b/packages/framework/tests/Unit/FilesystemFindFilesTest.php @@ -130,6 +130,13 @@ public function testFindFilesWithCaseInsensitiveExtensionFilter() $this->assertSameArray(['file.MD', 'another_file.md'], 'directory', 'MD'); } + public function testFindFilesWithLeadingDotInFileExtension() + { + $this->files(['directory/file.md', 'directory/another_file.md', 'directory/ignored.txt']); + $this->assertSameArray(['file.md', 'another_file.md'], 'directory', 'md'); + $this->assertSameArray(['file.md', 'another_file.md'], 'directory', '.md'); + } + public function testFindFilesHandlesLargeNumberOfFiles() { $this->files(array_map(fn ($i) => "directory/file$i.md", range(1, 100)));