Skip to content

Commit

Permalink
Match extensions case insensitivly
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Dec 14, 2024
1 parent 7750c99 commit cf7eb8e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/framework/src/Foundation/Kernel/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ public function findFiles(string $directory, string|false $matchExtension = fals
$finder->depth('== 0');
}

// Optionally match file extensions
// Optionally match file extensions (case-insensitively)
if ($matchExtension !== false) {
$finder->name('*.'.$matchExtension);
$finder->name('/\.' . preg_quote($matchExtension, '/') . '$/i');
}

// Collect relative paths
Expand Down
8 changes: 7 additions & 1 deletion packages/framework/tests/Unit/FilesystemFindFilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function testFindFilesWithEmptyExtensionFilter()
public function testFindFilesWithCaseInsensitiveExtensions()
{
$this->files(['directory/file.MD', 'directory/another_file.md', 'directory/ignored.TXT']);
$this->assertSameArray(['another_file.md'], 'directory', 'md');
$this->assertSameArray(['file.MD', 'another_file.md'], 'directory', 'md');
}

public function testFindFilesWithCaseInsensitiveFilenames()
Expand All @@ -124,6 +124,12 @@ public function testFindFilesWithCaseInsensitiveFilenames()
$this->assertSameArray(['file.md', 'anotherFile.md', 'ANOTHER_FILE.md'], 'directory');
}

public function testFindFilesWithCaseInsensitiveExtensionFilter()
{
$this->files(['directory/file.MD', 'directory/another_file.md', 'directory/ignored.TXT']);
$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)));
Expand Down

0 comments on commit cf7eb8e

Please sign in to comment.