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

This commit is contained in:
Simey Lameze
2021-12-02 16:58:27 +08:00
parent ceae073d1d
commit c82692e7a8
+10 -2
View File
@@ -562,8 +562,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);