From c9d440ce09f5f01455d05512380677ed3d478179 Mon Sep 17 00:00:00 2001 From: antoine Date: Fri, 20 Mar 2026 15:43:57 +0100 Subject: [PATCH 1/2] Improve FileUtil --- src/Utils/FileUtil.php | 10 +++++----- tests/Unit/Utils/FileUtilTest.php | 9 +++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Utils/FileUtil.php b/src/Utils/FileUtil.php index 304b3f83c..1b1b3ff98 100644 --- a/src/Utils/FileUtil.php +++ b/src/Utils/FileUtil.php @@ -23,12 +23,12 @@ public function findAvailableName(string $fileName, string $path = '', string $d public function explodeExtension(string $fileName): array { - if (($pos = strrpos($fileName, '.')) !== false) { - $ext = substr($fileName, $pos); - $fileName = substr($fileName, 0, $pos); - } + $pathinfo = pathinfo($fileName); - return [$fileName, $ext ?? '']; + return [ + $pathinfo['filename'] ?? '', + isset($pathinfo['extension']) ? '.'.$pathinfo['extension'] : '', + ]; } private function normalizeName(string $fileName): array|string|null diff --git a/tests/Unit/Utils/FileUtilTest.php b/tests/Unit/Utils/FileUtilTest.php index 1a8a2b9d7..8419dba7f 100644 --- a/tests/Unit/Utils/FileUtilTest.php +++ b/tests/Unit/Utils/FileUtilTest.php @@ -47,3 +47,12 @@ $fileUtil->findAvailableName('ôéàtest*.txt', 'tmp', 'local'), ); }); + +it('don’t care about relative path', function () { + $fileUtil = new FileUtil(); + + $this->assertEquals( + 'test.txt', + $fileUtil->findAvailableName('../../../test.txt', 'tmp', 'local'), + ); +}); From a26787fdb9fd05f3f2262b34fc6e5ea86c4d5249 Mon Sep 17 00:00:00 2001 From: antoine Date: Fri, 20 Mar 2026 16:02:08 +0100 Subject: [PATCH 2/2] naming --- tests/Unit/Utils/FileUtilTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/Utils/FileUtilTest.php b/tests/Unit/Utils/FileUtilTest.php index 8419dba7f..e1b42eaf8 100644 --- a/tests/Unit/Utils/FileUtilTest.php +++ b/tests/Unit/Utils/FileUtilTest.php @@ -48,7 +48,7 @@ ); }); -it('don’t care about relative path', function () { +it('doesn’t care about relative path', function () { $fileUtil = new FileUtil(); $this->assertEquals(