r103590 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103589‎ | r103590 | r103591 >
Date:14:52, 18 November 2011
Author:danwe
Status:deferred
Tags:
Comment:
isValidRegex() regex check improved and unsetHash() now returns whether hash did exist
Modified paths:
  • /trunk/extensions/HashTables/HashTables.php (modified) (history)

Diff [purge]

Index: trunk/extensions/HashTables/HashTables.php
@@ -340,7 +340,7 @@
341341 else {
342342 // reset specific hash tables:
343343 foreach( $args as $arg ) {
344 - $hashId = trim( $frame->expand($arg) );
 344+ $hashId = trim( $frame->expand( $arg ) );
345345 $store->unsetHash( $hashId );
346346
347347 }
@@ -783,14 +783,21 @@
784784 }
785785
786786 /**
787 - * Allows to unset a certain variable
 787+ * Allows to unset a certain hash. Returns whether the hash existed or not.
788788 *
789789 * @since 0.8
790790 *
791 - * @param type $varName
 791+ * @param string $varName
 792+ *
 793+ * @return boolean
792794 */
793795 public function unsetHash( $hashId ) {
794 - unset( $this->mHashTables[ $hashId ] );
 796+ $hashId = trim( $hashId );
 797+ if( $this->hashExists( $hashId ) ) {
 798+ unset( $this->mHashTables[ $hashId ] );
 799+ return true;
 800+ }
 801+ return false;
795802 }
796803
797804 /**
@@ -801,7 +808,13 @@
802809 * @return boolean
803810 */
804811 static function isValidRegEx( $pattern ) {
805 - return preg_match( '/^([\\/\\|%]).*\\1[imsSuUx]*$/', $pattern );
 812+ if( ! preg_match( '/^([\\/\\|%]).*\\1[imsSuUx]*$/', $pattern ) ) {
 813+ return false;
 814+ }
 815+ wfSuppressWarnings(); // instead of using the evil @ operator!
 816+ $isValid = false !== preg_match( $pattern, ' ' ); // preg_match returns false on error
 817+ wfRestoreWarnings();
 818+ return $isValid;
806819 }
807820
808821 }

Status & tagging log