mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #901 from halkyon/filenamefilter_underscores_fix
BUG FileNameFilter should remove any amount of underscores from start of...
This commit is contained in:
commit
a29bca3aa4
@ -41,7 +41,7 @@ class FileNameFilter extends Object {
|
||||
'/_/' => '-', // underscores to dashes
|
||||
'/[^A-Za-z0-9+.-]+/' => '', // remove non-ASCII chars, only allow alphanumeric plus dash and dot
|
||||
'/[\-]{2,}/' => '-', // remove duplicate dashes
|
||||
'/^[\.\-_]/' => '', // Remove all leading dots, dashes or underscores
|
||||
'/^[\.\-_]+/' => '', // Remove all leading dots, dashes or underscores
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -54,4 +54,58 @@ class FileNameFilterTest extends SapphireTest {
|
||||
);
|
||||
}
|
||||
|
||||
function testUnderscoresStartOfNameRemoved() {
|
||||
$name = '_test.txt';
|
||||
$filter = new FileNameFilter();
|
||||
$this->assertEquals('test.txt', $filter->filter($name));
|
||||
}
|
||||
|
||||
function testDoubleUnderscoresStartOfNameRemoved() {
|
||||
$name = '__test.txt';
|
||||
$filter = new FileNameFilter();
|
||||
$this->assertEquals('test.txt', $filter->filter($name));
|
||||
}
|
||||
|
||||
function testDotsStartOfNameRemoved() {
|
||||
$name = '.test.txt';
|
||||
$filter = new FileNameFilter();
|
||||
$this->assertEquals('test.txt', $filter->filter($name));
|
||||
}
|
||||
|
||||
function testDoubleDotsStartOfNameRemoved() {
|
||||
$name = '..test.txt';
|
||||
$filter = new FileNameFilter();
|
||||
$this->assertEquals('test.txt', $filter->filter($name));
|
||||
}
|
||||
|
||||
function testMixedInvalidCharsStartOfNameRemoved() {
|
||||
$name = '..#@$#@$^__test.txt';
|
||||
$filter = new FileNameFilter();
|
||||
$this->assertEquals('test.txt', $filter->filter($name));
|
||||
}
|
||||
|
||||
function testWhitespaceRemoved() {
|
||||
$name = ' test doc.txt';
|
||||
$filter = new FileNameFilter();
|
||||
$this->assertEquals('test-doc.txt', $filter->filter($name));
|
||||
}
|
||||
|
||||
function testUnderscoresReplacedWithDashes() {
|
||||
$name = 'test_doc.txt';
|
||||
$filter = new FileNameFilter();
|
||||
$this->assertEquals('test-doc.txt', $filter->filter($name));
|
||||
}
|
||||
|
||||
function testNonAsciiCharsReplacedWithDashes() {
|
||||
$name = '!@#$%^test_123@##@$#%^.txt';
|
||||
$filter = new FileNameFilter();
|
||||
$this->assertEquals('test-123.txt', $filter->filter($name));
|
||||
}
|
||||
|
||||
function testDuplicateDashesRemoved() {
|
||||
$name = 'test--document.txt';
|
||||
$filter = new FileNameFilter();
|
||||
$this->assertEquals('test-document.txt', $filter->filter($name));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user