diff --git a/calendar/lib.php b/calendar/lib.php index bd014951d6c..86186365b81 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -3588,6 +3588,18 @@ function calendar_get_view(\calendar_information $calendar, $view, $includenavig } } + // Check if $data has events. + if (isset($data->events)) { + // Let's check and sanitize all "name" in $data->events before it's sent to front end. + foreach ($data->events as $d) { + $name = $d->name ?? null; + // Encode special characters if our decoded name does not match the original name. + if ($name && (html_entity_decode($name) !== $name)) { + $d->name = htmlspecialchars(html_entity_decode($name), ENT_QUOTES, 'utf-8'); + } + } + } + return [$data, $template]; }