Skip to content

Commit 38174fd

Browse files
authored
Fix deletion of files without extension (#3664)
1 parent b091d25 commit 38174fd

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Support/FileRemover/DefaultFileRemover.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function removeFromMediaDirectory(Media $media, string $disk): void
3737
$imagePaths = array_filter(
3838
$allFilePaths,
3939
function (string $path) use ($media) {
40-
return Str::contains($path, pathinfo($media->file_name, PATHINFO_FILENAME).'.');
40+
return Str::afterLast($path, '/') === $media->file_name;
4141
}
4242
);
4343
foreach ($imagePaths as $imagePath) {

tests/Feature/Media/DeleteTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@
3030
expect(File::isDirectory($this->getMediaDirectory($media->id)))->toBeFalse();
3131
});
3232

33+
it('will remove the files without extension', function () {
34+
$media = $this->testModel->addMedia($this->getTestImageWithoutExtension())->toMediaCollection('images');
35+
36+
expect(File::isDirectory($this->getMediaDirectory($media->id)))->toBeTrue();
37+
38+
$media->delete();
39+
40+
expect(File::isDirectory($this->getMediaDirectory($media->id)))->toBeFalse();
41+
});
42+
3343
it('will remove files when deleting a media object with a custom path generator', function () {
3444
config(['media-library.path_generator' => TestPathGenerator::class]);
3545

0 commit comments

Comments
 (0)