Skip to content

Commit

Permalink
Use regex to detect part files
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Petry committed Mar 24, 2017
1 parent 4c2358c commit 6799445
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/private/legacy/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -1439,8 +1439,8 @@ public static function isValidFileName($file) {
return false;
}

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

Expand Down
10 changes: 10 additions & 0 deletions tests/lib/UtilTest.php
Original file line number Diff line number Diff line change
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 6799445

Please sign in to comment.