r91947 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91946‎ | r91947 | r91948 >
Date:11:33, 12 July 2011
Author:nad
Status:resolved (Comments)
Tags:
Comment:
escape brackets before using in regex for filtering matching records by field
Modified paths:
  • /trunk/extensions/RecordAdmin/RecordAdmin.php (modified) (history)
  • /trunk/extensions/RecordAdmin/RecordAdmin_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/RecordAdmin/RecordAdmin_body.php
@@ -281,14 +281,17 @@
282282 * - $b is the expression from the recordtable query
283283 */
284284 function cmpCallback( $a, $b, $operator ) {
285 - $b = str_replace( '/', '\/', html_entity_decode( $b, ENT_QUOTES ) );
 285+ $b = html_entity_decode( $b, ENT_QUOTES );
 286+ $bre = str_replace( '/', '\/', $b );
 287+ $bre = str_replace( '(', '\(', $bre );
 288+ $bre = str_replace( ')', '\)', $bre );
286289 switch ( $operator ) {
287290 case '=':
288 - $cond = preg_match( "/$b/i", $a );
 291+ $cond = preg_match( "/$bre/i", $a );
289292 break;
290293
291294 case '!=':
292 - $cond = !preg_match( "/$b/i", $a );
 295+ $cond = !preg_match( "/$bre/i", $a );
293296 break;
294297
295298 default:
Index: trunk/extensions/RecordAdmin/RecordAdmin.php
@@ -10,7 +10,7 @@
1111 * @author Siebrand Mazeland
1212 * @licence GNU General Public Licence 2.0 or later
1313 */
14 -define( 'RECORDADMIN_VERSION', '1.2.6, 2011-07-12' );
 14+define( 'RECORDADMIN_VERSION', '1.2.7, 2011-07-12' );
1515
1616 $dir = dirname( __FILE__ ) . '/';
1717 $wgExtensionMessagesFiles['RecordAdmin'] = $dir . 'RecordAdmin.i18n.php';

Comments

#Comment by Nikerabbit (talk | contribs)   13:16, 12 July 2011

I think you are looking for preg_quote( $foo, '/' );

Status & tagging log