Skip to content

Commit

Permalink
Merge pull request #27269 from owncloud/upload_filter_issue7496_backend
Browse files Browse the repository at this point in the history
#7496 Don`t allow upload of files with extension .part
  • Loading branch information
Vincent Petry committed Mar 29, 2017
2 parents ff126a5 + 6799445 commit 6ee78af
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/private/legacy/util.php
Expand Up @@ -1402,6 +1402,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
10 changes: 10 additions & 0 deletions tests/lib/UtilTest.php
Expand Up @@ -10,6 +10,9 @@

use OC_Util;

/**
* @group DB
*/
class UtilTest extends \Test\TestCase {
public function testGetVersion() {
$version = \OCP\Util::getVersion();
Expand Down Expand Up @@ -234,6 +237,13 @@ public function filenameValidationProvider() {
['.. ', 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

0 comments on commit 6ee78af

Please sign in to comment.