From 28f9c522a7de7c13f8997837026be7673da466d4 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Tue, 24 Nov 2020 00:07:18 +0000 Subject: [PATCH] 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. --- lib/adminlib.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/adminlib.php b/lib/adminlib.php index e29a82cd519..e6cc9dbd904 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -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; } /**