mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
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:
parent
b1d5e97a3d
commit
3b06e30558
@ -77,7 +77,8 @@ class FileNameFilter extends Object
|
|||||||
// Safeguard against empty file names
|
// Safeguard against empty file names
|
||||||
$nameWithoutExt = pathinfo($name, PATHINFO_FILENAME);
|
$nameWithoutExt = pathinfo($name, PATHINFO_FILENAME);
|
||||||
if (empty($nameWithoutExt)) {
|
if (empty($nameWithoutExt)) {
|
||||||
$name = $this->getDefaultName() . '.' . $ext;
|
$name = $this->getDefaultName();
|
||||||
|
$name .= $ext ? '.' . $ext : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $name;
|
return $name;
|
||||||
|
@ -142,4 +142,11 @@ class FileNameFilterTest extends SapphireTest
|
|||||||
$filter = new FileNameFilter();
|
$filter = new FileNameFilter();
|
||||||
$this->assertEquals('test-document.txt', $filter->filter($name));
|
$this->assertEquals('test-document.txt', $filter->filter($name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDoesntAddExtensionWhenMissing()
|
||||||
|
{
|
||||||
|
$name = 'no-extension';
|
||||||
|
$filter = new FileNameFilter();
|
||||||
|
$this->assertEquals('no-extension', $filter->filter($name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user