From d1076e3ef5d36309c8cc7a039ed077d333c9e20d Mon Sep 17 00:00:00 2001 From: John Okely Date: Wed, 19 Apr 2017 15:07:31 +0800 Subject: [PATCH] MDL-58632 assignsubmission_file: Don't allow any extension --- mod/assign/submission/file/locallib.php | 13 ++++--------- .../file/tests/behat/file_type_restriction.feature | 2 +- mod/assign/submission/file/tests/locallib_test.php | 8 ++++---- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/mod/assign/submission/file/locallib.php b/mod/assign/submission/file/locallib.php index b0816c3a2be..e2fe32f698b 100644 --- a/mod/assign/submission/file/locallib.php +++ b/mod/assign/submission/file/locallib.php @@ -678,15 +678,10 @@ class assign_submission_file extends assign_submission_plugin { private function get_nonexistent_file_types($types) { $nonexistent = []; foreach ($this->get_typesets($types) as $type) { - $coretypes = core_filetypes::get_types(); - // We can allow any extension, but validate groups & mimetypes. - if (strpos($type, '.') === false) { - // If there's no dot, check if it's a group. - $extensions = file_get_typegroup('extension', [$type]); - if (empty($extensions)) { - // If there's no extensions under that group, it doesn't exist. - $nonexistent[$type] = true; - } + // If there's no extensions under that group, it doesn't exist. + $extensions = file_get_typegroup('extension', [$type]); + if (empty($extensions)) { + $nonexistent[$type] = true; } } return array_keys($nonexistent); diff --git a/mod/assign/submission/file/tests/behat/file_type_restriction.feature b/mod/assign/submission/file/tests/behat/file_type_restriction.feature index 4990daece70..34f1c07837a 100644 --- a/mod/assign/submission/file/tests/behat/file_type_restriction.feature +++ b/mod/assign/submission/file/tests/behat/file_type_restriction.feature @@ -30,7 +30,7 @@ Feature: In an assignment, limit submittable file types And I navigate to "Edit settings" in current page administration When I set the field "Accepted file types" to "image/png;doesntexist;.anything;unreal/mimetype;nodot" And I press "Save and display" - And I should see "The following file types were not recognised: doesntexist unreal/mimetype nodot" + And I should see "The following file types were not recognised: doesntexist .anything unreal/mimetype nodot" And I set the field "Accepted file types" to "image/png;spreadsheet" And I press "Save and display" And I navigate to "Edit settings" in current page administration diff --git a/mod/assign/submission/file/tests/locallib_test.php b/mod/assign/submission/file/tests/locallib_test.php index c8b1082bdaf..618a787b129 100644 --- a/mod/assign/submission/file/tests/locallib_test.php +++ b/mod/assign/submission/file/tests/locallib_test.php @@ -144,13 +144,13 @@ class assignsubmission_file_locallib_testcase extends advanced_testcase { */ public function get_nonexistent_file_types_provider() { return [ - 'Nonexistent extensions are allowed' => [ + 'Nonexistent extensions are not allowed' => [ 'filetypes' => '.rat', - 'expected' => [] + 'expected' => ['.rat'] ], - 'Multiple nonexistent extensions are allowed' => [ + 'Multiple nonexistent extensions are not allowed' => [ 'filetypes' => '.ricefield .rat', - 'expected' => [] + 'expected' => ['.ricefield', '.rat'] ], 'Existent extension is allowed' => [ 'filetypes' => '.xml',