mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUG FileNameFilter should remove any amount of underscores from start of filename
When a user renames a file to "__test.txt" (two underscores or more), then FileNameFilter will only remove the very first underscore from the filename. This is not sufficient, as any number of underscores in the filename will be problematic when Filesystem::sync() is called, it will remove that File record thinking it's an internal file. This fixes it so any number of underscores are stripped out at the start of the filename.
This commit is contained in:
parent
624f427c2a
commit
1ce279ec9d
@ -41,7 +41,7 @@ class FileNameFilter extends Object {
|
|||||||
'/_/' => '-', // underscores to dashes
|
'/_/' => '-', // underscores to dashes
|
||||||
'/[^A-Za-z0-9+.-]+/' => '', // remove non-ASCII chars, only allow alphanumeric plus dash and dot
|
'/[^A-Za-z0-9+.-]+/' => '', // remove non-ASCII chars, only allow alphanumeric plus dash and dot
|
||||||
'/[\-]{2,}/' => '-', // remove duplicate dashes
|
'/[\-]{2,}/' => '-', // remove duplicate dashes
|
||||||
'/^[\.\-_]/' => '', // Remove all leading dots, dashes or underscores
|
'/^[\.\-_]+/' => '', // Remove all leading dots, dashes or underscores
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,4 +54,16 @@ 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));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user