From a66784ec989eb0e5d9c136651a4075f8bf962428 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sat, 20 Sep 2008 06:18:43 +0000 Subject: [PATCH] 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. --- includes/SearchEngine.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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"; -- 2.20.1