The problem also applies to all the other regex special chars: try it out with ....
authorAryeh Gregor <simetrical@users.mediawiki.org>
Thu, 17 Apr 2008 15:59:49 +0000 (15:59 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Thu, 17 Apr 2008 15:59:49 +0000 (15:59 +0000)
RELEASE-NOTES
includes/SearchEngine.php

index 33d9d0c..5b7509d 100644 (file)
@@ -190,8 +190,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 13756) Don't show the form and navigation links of Special:Newpages if
   the page is included
 * When hiding things on WhatLinksHere, generated URLs should hide them too
-* Properly escape search terms with forward slashes so they appear highlighted 
-  in search results.
+* Properly escape search terms with regex chars so they appear highlighted in
+  search results
 
 
 === API changes in 1.13 ===
index 864be9d..6af2bb3 100644 (file)
@@ -545,7 +545,7 @@ class SearchResult {
        }
 
        /**
-        * @param array $terms terms to highlight
+        * @param array $terms Terms to highlight (unescaped)
         * @return string highlighted text snippet, null (and not '') if not supported 
         */
        function getTextSnippet($terms){
@@ -559,7 +559,7 @@ class SearchResult {
         * Default implementation of snippet extraction
         *
         * @param string $text
-        * @param array $terms
+        * @param array $terms Terms to highlight (unescaped)
         * @param int $contextlines
         * @param int $contextchars
         * @return string
@@ -569,9 +569,11 @@ class SearchResult {
                $fname = __METHOD__;
        
                $lines = explode( "\n", $text );
-               
+
+               foreach( $terms as $index => $term ) {
+                       $terms[$index] = preg_quote( $term, '/' );
+               }
                $terms = implode( '|', $terms );
-               $terms = str_replace( '/', "\\/", $terms);
                $max = intval( $contextchars ) + 1;
                $pat1 = "/(.*)($terms)(.{0,$max})/i";