From 9c1427c036521be5d9127b813bdf51ddcf839345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Suwi=C5=84ski?= Date: Tue, 24 May 2022 16:17:12 +0200 Subject: [PATCH] fallback to default on post filter empty basename --- src/FileNameFilter.php | 2 +- tests/php/FileNameFilterTest.php | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/FileNameFilter.php b/src/FileNameFilter.php index dea13ee7..485ca46a 100644 --- a/src/FileNameFilter.php +++ b/src/FileNameFilter.php @@ -81,7 +81,7 @@ public function filter($name) // Safeguard against empty file names $nameWithoutExt = pathinfo($name ?? '', PATHINFO_FILENAME); - if (empty($nameWithoutExt)) { + if ($name === $ext || empty($nameWithoutExt)) { $name = $this->getDefaultName(); $name .= $ext ? '.' . $ext : ''; } diff --git a/tests/php/FileNameFilterTest.php b/tests/php/FileNameFilterTest.php index 37727e56..e5f986f6 100644 --- a/tests/php/FileNameFilterTest.php +++ b/tests/php/FileNameFilterTest.php @@ -59,9 +59,11 @@ public function testFilterWithCustomRules() ); } - public function testFilterWithEmptyString() + /** + * @dataProvider providerFilterWithEmptyString + */ + public function testFilterWithEmptyString($name) { - $name = 'ö ö ö.jpg'; $filter = new FileNameFilter(); $filter->setTransliterator(new Transliterator()); $result = $filter->filter($name); @@ -78,6 +80,11 @@ public function testFilterWithEmptyString() ); } + public function providerFilterWithEmptyString() + { + return [['ö ö ö.jpg'], ['新しいファイル.jpg']]; + } + public function testUnderscoresStartOfNameRemoved() { $name = '_test.txt';