From d1b0786a5193293df0490a37fbac48593d2b8e97 Mon Sep 17 00:00:00 2001 From: sam marshall Date: Wed, 23 Oct 2013 15:30:27 +0100 Subject: [PATCH] MDL-34654 Glossary: ampersand breaks auto-linking --- filter/glossary/filter.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/filter/glossary/filter.php b/filter/glossary/filter.php index 259c668cc12..e696a37268e 100644 --- a/filter/glossary/filter.php +++ b/filter/glossary/filter.php @@ -131,6 +131,11 @@ class filter_glossary extends moodle_text_filter { foreach ($concepts as $key => $concept) { // Trim empty or unlinkable concepts $currentconcept = trim(strip_tags($concept->concept)); + + // Concept must be HTML-escaped, so do the same as print_string + // to turn ampersands into &. + $currentconcept = replace_ampersands_not_followed_by_entity($currentconcept); + if (empty($currentconcept)) { unset($concepts[$key]); continue; @@ -168,10 +173,14 @@ class filter_glossary extends moodle_text_filter { '&mode=cat&hook='.$concept->id.'">'; } else { // Link to entry or alias if (!empty($concept->originalconcept)) { // We are dealing with an alias (so show and point to original) - $title = str_replace('"', "'", strip_tags($glossaryname.': '.$concept->originalconcept)); + $title = str_replace('"', "'", html_entity_decode( + strip_tags($glossaryname.': '.$concept->originalconcept))); $concept->id = $concept->entryid; } else { // This is an entry - $title = str_replace('"', "'", strip_tags($glossaryname.': '.$concept->concept)); + // We need to remove entities from the content here because it + // will be escaped by html_writer below. + $title = str_replace('"', "'", html_entity_decode( + strip_tags($glossaryname.': '.$concept->concept))); } // hardcoding dictionary format in the URL rather than defaulting // to the current glossary format which may not work in a popup.