Verify parameter for MapCacheLRU::has() can be passed to array_key_exists()

This prevents warnings from PHP from array_key_exists().

Also make sure Title::newFromText throws an exception before it can trigger this.

Bug: T76305
Change-Id: I2b36b7a3b96b37e29fe06f69c13a185b3ec592a7
This commit is contained in:
Mark A. Hershberger 2014-11-30 15:16:04 -05:00 committed by Chad Horohoe
parent f6d852f6e9
commit 372ded2fea
3 changed files with 9 additions and 5 deletions

View file

@ -256,12 +256,12 @@ class Title {
* by a prefix. If you want to force a specific namespace even if
* $text might begin with a namespace prefix, use makeTitle() or
* makeTitleSafe().
* @throws MWException
* @throws InvalidArgumentException
* @return Title|null Title or null on an error.
*/
public static function newFromText( $text, $defaultNamespace = NS_MAIN ) {
if ( is_object( $text ) ) {
throw new MWException( 'Title::newFromText given an object' );
if ( !is_string( $text ) ) {
throw new InvalidArgumentException( 'Title::newFromText given something that isn\'t a string' );
}
$cache = self::getTitleCache();

View file

@ -74,7 +74,11 @@ class MapCacheLRU {
* @return bool
*/
public function has( $key ) {
return array_key_exists( $key, $this->cache );
if ( is_string( $key ) || is_integer( $key ) ) {
return array_key_exists( $key, $this->cache );
}
wfWarn( __METHOD__ . ": Key passed isn't a string or an integer.", 2 );
return false;
}
/**

View file

@ -97,7 +97,7 @@ class TestSample extends MediaWikiLangTestCase {
// @codingStandardsIgnoreStart Ignore long line warning
/**
* @expectedException MWException object
* @expectedException InvalidArgumentException
* See http://phpunit.de/manual/3.7/en/appendixes.annotations.html#appendixes.annotations.expectedException
*/
// @codingStandardsIgnoreEnd