Index: mod/data/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/data/lib.php,v
retrieving revision 1.70.2.5
diff -u -r1.70.2.5 lib.php
--- mod/data/lib.php	3 Jul 2006 21:07:41 -0000	1.70.2.5
+++ mod/data/lib.php	27 Sep 2006 18:22:41 -0000
@@ -822,6 +822,21 @@
    return $info;
 }
 
+
+// Escapes or replaces character sequences that would be interpreted as
+// special characters in the replacement string for preg_replace, namely
+// '$' and '\'. When found, a backslash is inserted before each, to
+// indicate that the actual character should be included.
+//
+// This probably could be used in other places and could be moved to
+// some other library, but I didn't see an obvious choice, so it's here
+// for now (where it was first needed).
+function data_protect_replacement_string($string)
+{
+    return preg_replace("/[\\$\\\\]./", "\\\\$0", $string);
+}
+
+
 ///junk functions
 /************************************************************************
  * takes a list of records, the current data, a search string,          *
@@ -866,7 +881,9 @@
     /// Then we generate strings to replace for normal tags
         foreach ($fields as $field) {
             $patterns[]='/\[\['.$field->field->name.'\]\]/i';
-            $replacement[] = highlight($search, $field->display_browse_field($record->id, $template));
+            $fieldval = $field->display_browse_field($record->id, $template);
+            $replacement[] = data_protect_replacement_string(
+                highlight($search, $fieldval));
         }
 
     /// Replacing special tags (##Edit##, ##Delete##, ##More##)
