Use regex to detect part files

This commit is contained in:
Vincent Petry 2017-03-24 11:28:54 +01:00 committed by Joas Schilling
parent 327094d557
commit 1c771c097a
No known key found for this signature in database
GPG Key ID: E166FD8976B3BAC8
2 changed files with 44 additions and 34 deletions

View File

@ -1389,8 +1389,8 @@ class OC_Util {
return false; return false;
} }
$path_parts = pathinfo($trimmed); // detect part files
if ($path_parts['extension'] === 'part') { if (preg_match('/' . \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX . '/', $trimmed) !== 0) {
return false; return false;
} }

View File

@ -204,41 +204,51 @@ class UtilTest extends \Test\TestCase {
} }
public function filenameValidationProvider() { public function filenameValidationProvider() {
return array( return [
// valid names // valid names
array('boringname', true), ['boringname', true],
array('something.with.extension', true), ['something.with.extension', true],
array('now with spaces', true), ['now with spaces', true],
array('.a', true), ['.a', true],
array('..a', true), ['..a', true],
array('.dotfile', true), ['.dotfile', true],
array('single\'quote', true), ['single\'quote', true],
array(' spaces before', true), [' spaces before', true],
array('spaces after ', true), ['spaces after ', true],
array('allowed chars including the crazy ones $%&_-^@!,()[]{}=;#', true), ['allowed chars including the crazy ones $%&_-^@!,()[]{}=;#', true],
array('汉字也能用', true), ['汉字也能用', true],
array('und Ümläüte sind auch willkommen', true), ['und Ümläüte sind auch willkommen', true],
// disallowed names // disallowed names
array('', false), ['', false],
array(' ', false), [' ', false],
array('.', false), ['.', false],
array('..', false), ['..', false],
array('back\\slash', false), ['back\\slash', false],
array('sl/ash', false), ['sl/ash', false],
array('lt<lt', true), ['lt<lt', true],
array('gt>gt', true), ['gt>gt', true],
array('col:on', true), ['col:on', true],
array('double"quote', true), ['double"quote', true],
array('pi|pe', true), ['pi|pe', true],
array('dont?ask?questions?', true), ['dont?ask?questions?', true],
array('super*star', true), ['super*star', true],
array('new\nline', false), ['new\nline', false],
// better disallow these to avoid unexpected trimming to have side effects // better disallow these to avoid unexpected trimming to have side effects
array(' ..', false), [' ..', false],
array('.. ', false), ['.. ', false],
array('. ', false), ['. ', false],
array(' .', false), [' .', false],
);
// part files not allowed
['.part', false],
['notallowed.part', false],
['neither.filepart', false],
// part in the middle is ok
['super movie part one.mkv', true],
['super.movie.part.mkv', true],
];
} }
/** /**