MDL-73195 mod_url: prevent invalid urls from breaking the course

This commit is contained in:
Simey Lameze
2021-11-29 20:19:59 +08:00
parent 4f270213e7
commit fda79a220b
+10 -2
View File
@@ -571,8 +571,16 @@ function url_guess_icon($fullurl, $size = null) {
return null;
}
$moodleurl = new moodle_url($fullurl);
$fullurl = $moodleurl->out_omit_querystring();
try {
// There can be some cases where the url is invalid making parse_url() to return false.
// That will make moodle_url class to throw an exception, so we need to catch the exception to prevent errors.
$moodleurl = new moodle_url($fullurl);
$fullurl = $moodleurl->out_omit_querystring();
} catch (\moodle_exception $e) {
// If an exception is thrown, means the url is invalid. No need to log exception.
return null;
}
$icon = file_extension_icon($fullurl, $size);
$htmlicon = file_extension_icon('.htm', $size);
$unknownicon = file_extension_icon('', $size);