From fda79a220ba2d69b7f56b3a67c67f8471fc00a5a Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Mon, 29 Nov 2021 20:19:59 +0800 Subject: [PATCH] MDL-73195 mod_url: prevent invalid urls from breaking the course --- mod/url/locallib.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mod/url/locallib.php b/mod/url/locallib.php index 00240f48e13..c7c455e5baf 100644 --- a/mod/url/locallib.php +++ b/mod/url/locallib.php @@ -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);