Merge "Make MapCacheLRU throw errors for bad $field arguments"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 14 Aug 2018 01:17:17 +0000 (01:17 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 14 Aug 2018 01:17:17 +0000 (01:17 +0000)
1  2 
includes/libs/MapCacheLRU.php

@@@ -64,7 -64,7 +64,7 @@@ class MapCacheLRU implements IExpiringS
                Assert::parameter( $maxKeys > 0, '$maxKeys', 'must be above zero' );
  
                $this->maxCacheKeys = $maxKeys;
 -              // Use the current time as the default "as of" timesamp of entries
 +              // Use the current time as the default "as of" timestamp of entries
                $this->epoch = $this->getCurrentTime();
        }
  
        public function has( $key, $maxAge = 0.0 ) {
                if ( !is_int( $key ) && !is_string( $key ) ) {
                        throw new UnexpectedValueException(
-                               __METHOD__ . ' called with invalid key. Must be string or integer.' );
+                               __METHOD__ . ': invalid key; must be string or integer.' );
                }
  
                if ( !array_key_exists( $key, $this->cache ) ) {
                        $this->set( $key, [], $initRank );
                }
  
+               if ( !is_int( $field ) && !is_string( $field ) ) {
+                       throw new UnexpectedValueException(
+                               __METHOD__ . ": invalid field for '$key'; must be string or integer." );
+               }
                if ( !is_array( $this->cache[$key] ) ) {
                        throw new UnexpectedValueException( "The value of '$key' is not an array." );
                }
         */
        public function hasField( $key, $field, $maxAge = 0.0 ) {
                $value = $this->get( $key );
+               if ( !is_int( $field ) && !is_string( $field ) ) {
+                       throw new UnexpectedValueException(
+                               __METHOD__ . ": invalid field for '$key'; must be string or integer." );
+               }
                if ( !is_array( $value ) || !array_key_exists( $field, $value ) ) {
                        return false;
                }