Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fallback to default on basename equals ext #495

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/FileNameFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 : '';
}
Expand Down
11 changes: 9 additions & 2 deletions tests/php/FileNameFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -78,6 +80,11 @@ public function testFilterWithEmptyString()
);
}

public function providerFilterWithEmptyString()
{
return [['ö ö ö.jpg'], ['新しいファイル.jpg']];
}

public function testUnderscoresStartOfNameRemoved()
{
$name = '_test.txt';
Expand Down