Skip to content

Commit

Permalink
MDL-65355 course: Render course search encoded characters correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
rhell4 committed Jan 6, 2025
1 parent ab5692a commit bef1f59
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions course/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2022,7 +2022,12 @@ public function get_course_formatted_summary($course, $options = array()) {
$summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course', 'summary', null);
$summary = format_text($summary, $course->summaryformat, $options);
if (!empty($this->searchcriteria['search'])) {
$summary = highlight($this->searchcriteria['search'], $summary);
// The course summary we are highlighting might have encoded html entities or a mix of both decode and encoded entities.
// If we decode both the summary and search term, then encode just the ampersands, we should have matching strings,
// and any ampersands in the search term shouldn't break any html entities in the summary when being highlighted.
$summary = replace_ampersands_not_followed_by_entity(html_entity_decode($summary));
$search = replace_ampersands_not_followed_by_entity(html_entity_decode($this->searchcriteria['search']));
$summary = highlight($search, $summary);
}
return $summary;
}
Expand All @@ -2041,7 +2046,10 @@ public function get_course_formatted_name($course, $options = array()) {
}
$name = format_string(get_course_display_name_for_list($course), true, $options);
if (!empty($this->searchcriteria['search'])) {
$name = highlight($this->searchcriteria['search'], $name);
// The course name we are highlighting is a formatted string,
// so the search term should also be a formatted string to match.
$search = format_string($this->searchcriteria['search'], true, $options);
$name = highlight($search, $name);
}
return $name;
}
Expand Down

0 comments on commit bef1f59

Please sign in to comment.