r33489 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r33488‎ | r33489 | r33490 >
Date:15:59, 17 April 2008
Author:simetrical
Status:old
Tags:
Comment:
The problem also applies to all the other regex special chars: try it out with ., |, etc. Use preg_quote().
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/SearchEngine.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SearchEngine.php
@@ -545,7 +545,7 @@
546546 }
547547
548548 /**
549 - * @param array $terms terms to highlight
 549+ * @param array $terms Terms to highlight (unescaped)
550550 * @return string highlighted text snippet, null (and not '') if not supported
551551 */
552552 function getTextSnippet($terms){
@@ -559,7 +559,7 @@
560560 * Default implementation of snippet extraction
561561 *
562562 * @param string $text
563 - * @param array $terms
 563+ * @param array $terms Terms to highlight (unescaped)
564564 * @param int $contextlines
565565 * @param int $contextchars
566566 * @return string
@@ -569,9 +569,11 @@
570570 $fname = __METHOD__;
571571
572572 $lines = explode( "\n", $text );
573 -
 573+
 574+ foreach( $terms as $index => $term ) {
 575+ $terms[$index] = preg_quote( $term, '/' );
 576+ }
574577 $terms = implode( '|', $terms );
575 - $terms = str_replace( '/', "\\/", $terms);
576578 $max = intval( $contextchars ) + 1;
577579 $pat1 = "/(.*)($terms)(.{0,$max})/i";
578580
Index: trunk/phase3/RELEASE-NOTES
@@ -190,8 +190,8 @@
191191 * (bug 13756) Don't show the form and navigation links of Special:Newpages if
192192 the page is included
193193 * When hiding things on WhatLinksHere, generated URLs should hide them too
194 -* Properly escape search terms with forward slashes so they appear highlighted
195 - in search results.
 194+* Properly escape search terms with regex chars so they appear highlighted in
 195+ search results
196196
197197
198198 === API changes in 1.13 ===

Follow-up revisions

RevisionCommit summaryAuthorDate
r34086Revert for now:...brion20:55, 1 May 2008

Status & tagging log