Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/private/legacy/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,12 @@ public static function isValidFileName($file) {
if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) {
return false;
}

// detect part files
if (preg_match('/' . \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX . '/', $trimmed) !== 0) {
return false;
}

foreach (str_split($trimmed) as $char) {
if (strpos(\OCP\Constants::FILENAME_INVALID_CHARS, $char) !== false) {
return false;
Expand Down
74 changes: 42 additions & 32 deletions tests/lib/UtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,41 +204,51 @@ public function testFilenameValidation($file, $valid) {
}

public function filenameValidationProvider() {
return array(
return [
// valid names
array('boringname', true),
array('something.with.extension', true),
array('now with spaces', true),
array('.a', true),
array('..a', true),
array('.dotfile', true),
array('single\'quote', true),
array(' spaces before', true),
array('spaces after ', true),
array('allowed chars including the crazy ones $%&_-^@!,()[]{}=;#', true),
array('汉字也能用', true),
array('und Ümläüte sind auch willkommen', true),
['boringname', true],
['something.with.extension', true],
['now with spaces', true],
['.a', true],
['..a', true],
['.dotfile', true],
['single\'quote', true],
[' spaces before', true],
['spaces after ', true],
['allowed chars including the crazy ones $%&_-^@!,()[]{}=;#', true],
['汉字也能用', true],
['und Ümläüte sind auch willkommen', true],
// disallowed names
array('', false),
array(' ', false),
array('.', false),
array('..', false),
array('back\\slash', false),
array('sl/ash', false),
array('lt<lt', true),
array('gt>gt', true),
array('col:on', true),
array('double"quote', true),
array('pi|pe', true),
array('dont?ask?questions?', true),
array('super*star', true),
array('new\nline', false),
['', false],
[' ', false],
['.', false],
['..', false],
['back\\slash', false],
['sl/ash', false],
['lt<lt', true],
['gt>gt', true],
['col:on', true],
['double"quote', true],
['pi|pe', true],
['dont?ask?questions?', true],
['super*star', true],
['new\nline', false],

// better disallow these to avoid unexpected trimming to have side effects
array(' ..', false),
array('.. ', false),
array('. ', false),
array(' .', false),
);
[' ..', false],
['.. ', false],
['. ', 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],
];
}

/**
Expand Down