mirror of
https://github.com/moodle/moodle.git
synced 2025-03-17 14:10:08 +01:00
MDL-58632 assignsubmission_file: Don't allow any extension
This commit is contained in:
parent
faedb2736e
commit
d1076e3ef5
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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',
|
||||
|
Loading…
x
Reference in New Issue
Block a user