From 2a5618437e67a2d4404f64f29f59fdd4f4a38e93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Baconnier?= Date: Tue, 9 Jul 2024 10:23:37 +0200 Subject: [PATCH] Fix deletion of files without extension --- src/Support/FileRemover/DefaultFileRemover.php | 2 +- tests/Feature/Media/DeleteTest.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Support/FileRemover/DefaultFileRemover.php b/src/Support/FileRemover/DefaultFileRemover.php index 53c489c11..5cccd9be1 100644 --- a/src/Support/FileRemover/DefaultFileRemover.php +++ b/src/Support/FileRemover/DefaultFileRemover.php @@ -37,7 +37,7 @@ public function removeFromMediaDirectory(Media $media, string $disk): void $imagePaths = array_filter( $allFilePaths, function (string $path) use ($media) { - return Str::contains($path, pathinfo($media->file_name, PATHINFO_FILENAME).'.'); + return Str::afterLast($path, '/') === $media->file_name; } ); foreach ($imagePaths as $imagePath) { diff --git a/tests/Feature/Media/DeleteTest.php b/tests/Feature/Media/DeleteTest.php index a0248287f..4577a661f 100644 --- a/tests/Feature/Media/DeleteTest.php +++ b/tests/Feature/Media/DeleteTest.php @@ -30,6 +30,16 @@ expect(File::isDirectory($this->getMediaDirectory($media->id)))->toBeFalse(); }); +it('will remove the files without extension', function () { + $media = $this->testModel->addMedia($this->getTestImageWithoutExtension())->toMediaCollection('images'); + + expect(File::isDirectory($this->getMediaDirectory($media->id)))->toBeTrue(); + + $media->delete(); + + expect(File::isDirectory($this->getMediaDirectory($media->id)))->toBeFalse(); +}); + it('will remove files when deleting a media object with a custom path generator', function () { config(['media-library.path_generator' => TestPathGenerator::class]);