MDL-68927 admin: stricter validation of unknown file types.

If a given file type is unknown, then return an error string. This
matches implementation in the form field element of the same type.
This commit is contained in:
Paul Holden
2021-05-17 11:28:04 +01:00
parent 0b69b37f04
commit 28f9c522a7
+15 -9
View File
@@ -11378,16 +11378,22 @@ class admin_setting_filetypes extends admin_setting_configtext {
* @return bool|string True if ok, the string if error found
*/
public function validate($data) {
// No need to call parent's validation here as we are PARAM_RAW.
if ($this->util->is_listed($data, $this->onlytypes)) {
return true;
} else {
$troublemakers = $this->util->get_not_listed($data, $this->onlytypes);
return get_string('filetypesnotallowed', 'core_form', implode(' ', $troublemakers));
$parentcheck = parent::validate($data);
if ($parentcheck !== true) {
return $parentcheck;
}
// Check for unknown file types.
if ($unknown = $this->util->get_unknown_file_types($data)) {
return get_string('filetypesunknown', 'core_form', implode(', ', $unknown));
}
// Check for disallowed file types.
if ($notlisted = $this->util->get_not_listed($data, $this->onlytypes)) {
return get_string('filetypesnotallowed', 'core_form', implode(', ', $notlisted));
}
return true;
}
/**