From: Tim Starling Date: Sat, 20 Sep 2008 06:18:43 +0000 (+0000) Subject: Don't double-escape search terms before highlighting. It's done once already SearchRe... X-Git-Tag: 1.31.0-rc.0~45204 X-Git-Url: http://git.cyclocoop.org/%22.%24image2.%22?a=commitdiff_plain;h=a66784ec989eb0e5d9c136651a4075f8bf962428;p=lhc%2Fweb%2Fwiklou.git Don't double-escape search terms before highlighting. It's done once already SearchResultSet::termMatches(). Doing it twice results in / -> \/ -> \\/, literal backslash followed by end of regex. Not obvious in SearchMySQL because of stripForSearch(), but visible in MWSearch. The fact that it's done in termMatches() already is hackish and undocumented, but I won't change it right now. --- diff --git a/includes/SearchEngine.php b/includes/SearchEngine.php index 72e0635c6e..1856b9e57a 100644 --- a/includes/SearchEngine.php +++ b/includes/SearchEngine.php @@ -741,13 +741,12 @@ class SearchHighlighter { // prepare regexps foreach( $terms as $index => $term ) { - $terms[$index] = preg_quote( $term, '/' ); // manually do upper/lowercase stuff for utf-8 since PHP won't do it if(preg_match('/[\x80-\xff]/', $term) ){ $terms[$index] = preg_replace_callback('/./us',array($this,'caseCallback'),$terms[$index]); + } else { + $terms[$index] = $term; } - - } $anyterm = implode( '|', $terms ); $phrase = implode("$wgSearchHighlightBoundaries+", $terms ); @@ -1077,11 +1076,10 @@ class SearchHighlighter { public function highlightSimple( $text, $terms, $contextlines, $contextchars ) { global $wgLang, $wgContLang; $fname = __METHOD__; - + $lines = explode( "\n", $text ); $terms = implode( '|', $terms ); - $terms = str_replace( '/', "\\/", $terms); $max = intval( $contextchars ) + 1; $pat1 = "/(.*)($terms)(.{0,$max})/i";