r75854 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75853‎ | r75854 | r75855 >
Date:15:26, 2 November 2010
Author:mah
Status:ok
Tags:
Comment:
follow up r75046: Quote regex chars in variable strings used in preg_*
Modified paths:
  • /trunk/extensions/RSS/RSS.php (modified) (history)

Diff [purge]

Index: trunk/extensions/RSS/RSS.php
@@ -326,7 +326,7 @@
327327 }
328328
329329 if ( isset( $item[$left] ) ) {
330 - $leftValue = preg_replace( '#{{{' . $left . '}}}#',
 330+ $leftValue = preg_replace( '/{{{' . preg_quote( $left, '/' ) . '}}}/',
331331 $item[$left], $bits[1] );
332332 $rendered[] = implode( '=', array( $left, $leftValue ) );
333333 } else {
@@ -388,13 +388,15 @@
389389
390390 if ( count( $filter ) == 0 ) return $filterType !== 'filterOut';
391391
392 - $match = preg_match( '#(' . implode( "|", $filter ) . ')#i', $text );
393 - if ( $match ) {
 392+ /* Using : for delimiter here since it'll be quoted automatically. */
 393+ $match = preg_match( ':(' . implode( "|", array_map('preg_quote', $filter ) ) . '):i', $text ) ;
 394+ if ( $match ) {
394395 return true;
395 - }
 396+ }
396397 return false;
397 - }
 398+ }
398399
 400+
399401 function highlightTerms( $text ) {
400402 $i = 0;
401403 $starttag = 'v8x5u3t3u8h';
@@ -409,7 +411,7 @@
410412
411413 foreach ( $this->highlight as $term ) {
412414 if ( $term ) {
413 - $text = preg_replace( "|\b(\w*?" . $term . "\w*?)\b|i", "$starttag" . "_" . $i . "\\1$endtag", $text );
 415+ $text = preg_replace( "/\b(\w*?" . preg_quote( $term, '/' ) . "\w*?)\b/i", "$starttag" . "_" . $i . "\\1$endtag", $text );
414416 $i++;
415417 if ( $i == $count_color ) {
416418 $i = 0;
@@ -419,7 +421,8 @@
420422
421423 # To avoid trouble should someone wants to highlight the terms "span", "style", …
422424 for ( $i = 0; $i < 5; $i++ ) {
423 - $text = preg_replace( "|$starttag" . "_" . $i . "|", "<span style=\"background-color:" . $color[$i] . "; font-weight: bold;\">", $text );
 425+ $text = preg_replace( "/$starttag" . "_" . preg_quote( $i, '/' ) . "/",
 426+ "<span style=\"background-color:" . $color[$i] . "; font-weight: bold;\">", $text );
424427 $text = preg_replace( "|$endtag|", '</span>', $text );
425428 }
426429

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r75046* Use [[Template:RSSPost]] (and [[Mediawiki:Rss-item]]) (or another...mah21:54, 19 October 2010

Status & tagging log