From 91a0aaea20f31462bc748c94370eb5fdc0d7e29f Mon Sep 17 00:00:00 2001 From: Ryan Davis <5921873+rmdavi@users.noreply.github.com> Date: Fri, 26 Jul 2024 03:43:05 -0400 Subject: [PATCH] Adjust check for php file extensions (#3681) Co-authored-by: Ryan Davis --- src/MediaCollections/FileAdder.php | 2 +- tests/MediaCollections/FileAdderTest.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/MediaCollections/FileAdder.php b/src/MediaCollections/FileAdder.php index bb3bf8111..a522ab91d 100644 --- a/src/MediaCollections/FileAdder.php +++ b/src/MediaCollections/FileAdder.php @@ -405,7 +405,7 @@ public function defaultSanitizer(string $fileName): string $sanitizedFileName = str_replace(['#', '/', '\\', ' '], '-', $sanitizedFileName); $phpExtensions = [ - 'php', 'php3', 'php4', 'php5', 'php7', 'php8', 'phtml', 'phar', + '.php', '.php3', '.php4', '.php5', '.php7', '.php8', '.phtml', '.phar', ]; if (Str::endsWith(strtolower($sanitizedFileName), $phpExtensions)) { diff --git a/tests/MediaCollections/FileAdderTest.php b/tests/MediaCollections/FileAdderTest.php index 46254f61c..e762e1b6b 100644 --- a/tests/MediaCollections/FileAdderTest.php +++ b/tests/MediaCollections/FileAdderTest.php @@ -30,3 +30,9 @@ $adder->defaultSanitizer('filename.php‎'); })->throws(FileNameNotAllowed::class); + +it('will not throw an exception if the sanitized file name ends with php but is not a php file', function () { + $adder = app(FileAdder::class); + + $adder->defaultSanitizer('media-libraryJQwPHp'); +})->throwsNoExceptions();