Don’t add extension dot in FileNameFilter

File names are generally valid without an extension (although they might be disallowed by upload constraints),
so the filter should deal gracefully with them (“myfile” should return “myfile”, not “myfile.”)
This commit is contained in:
Ingo Schommer 2017-01-13 10:40:44 +13:00
parent b1d5e97a3d
commit 3b06e30558
2 changed files with 9 additions and 1 deletions

View File

@ -77,7 +77,8 @@ class FileNameFilter extends Object
// Safeguard against empty file names
$nameWithoutExt = pathinfo($name, PATHINFO_FILENAME);
if (empty($nameWithoutExt)) {
$name = $this->getDefaultName() . '.' . $ext;
$name = $this->getDefaultName();
$name .= $ext ? '.' . $ext : '';
}
return $name;

View File

@ -142,4 +142,11 @@ class FileNameFilterTest extends SapphireTest
$filter = new FileNameFilter();
$this->assertEquals('test-document.txt', $filter->filter($name));
}
public function testDoesntAddExtensionWhenMissing()
{
$name = 'no-extension';
$filter = new FileNameFilter();
$this->assertEquals('no-extension', $filter->filter($name));
}
}