]> git.mjollnir.org Git - moodle.git/commitdiff
filterlib/filter_phrases() - try to escape magic characters used internally by the...
authormartinlanghoff <martinlanghoff>
Tue, 25 Apr 2006 22:47:42 +0000 (22:47 +0000)
committermartinlanghoff <martinlanghoff>
Tue, 25 Apr 2006 22:47:42 +0000 (22:47 +0000)
This is an attempt to fix filter problems caused by glossary matches on %
(which also affect matches on * and #). Works for the sample cases I have,
but we may be breaking subtly in other places.

lib/filterlib.php

index fcf037a26b31143f437f71843a5704fe63873e4b..00972bff2093604f844341c16ed4d466f3604cc6 100644 (file)
@@ -82,6 +82,9 @@ function filter_phrases ($text, &$link_array, $ignoretagsopen=NULL, $ignoretagsc
         foreach ($ignoretagsclose as $close) $filterignoretagsclose[] = $close;
     }
 
+    //// Double up some magic chars to avoid "accidental matches"
+    $text = preg_replace('/([#*%])/','\1\1',$text);
+
 
 ////Remove everything enclosed by the ignore tags from $text    
     filter_save_ignore_tags($text,$filterignoretagsopen,$filterignoretagsclose,$ignoretags);
@@ -115,6 +118,11 @@ function filter_phrases ($text, &$link_array, $ignoretagsopen=NULL, $ignoretagsc
                 $linkobject->work_hreftagbegin = $linkobject->hreftagbegin;
                 $linkobject->work_hreftagend   = $linkobject->hreftagend;
             }
+
+        /// Double up chars to protect true duplicates
+        /// be cleared up before returning to the user.
+            $linkobject->work_hreftagbegin = preg_replace('/([#*%])/','\1\1',$linkobject->work_hreftagbegin);
+
             if (empty($linkobject->casesensitive)) {
                 $linkobject->work_casesensitive = false;
             } else {
@@ -129,6 +137,9 @@ function filter_phrases ($text, &$link_array, $ignoretagsopen=NULL, $ignoretagsc
         /// Strip tags out of the phrase
             $linkobject->work_phrase = strip_tags($linkobject->phrase);
 
+        /// Double up chars that might cause a false match -- the duplicates will
+        /// be cleared up before returning to the user.
+            $linkobject->work_phrase = preg_replace('/([#*%])/','\1\1',$linkobject->work_phrase);
 
         /// Set the replacement phrase properly
             if ($linkobject->replacementphrase) {    //We have specified a replacement phrase
@@ -220,6 +231,9 @@ function filter_phrases ($text, &$link_array, $ignoretagsopen=NULL, $ignoretagsc
         $text = str_replace(array_keys($ignoretags),$ignoretags,$text);
     }
 
+    //// Remove the protective doubleups 
+    $text =  preg_replace('/([#*%])(\1)/','\1',$text);
+
 /// Add missing javascript for popus
     $text = filter_add_javascript($text);