From 372ded2fea436bf0e61318991f903d61bde26366 Mon Sep 17 00:00:00 2001 From: "Mark A. Hershberger" Date: Sun, 30 Nov 2014 15:16:04 -0500 Subject: [PATCH] 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 --- includes/Title.php | 6 +++--- includes/libs/MapCacheLRU.php | 6 +++++- tests/phpunit/includes/SampleTest.php | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index 921538b287..9868b2e8d6 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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(); diff --git a/includes/libs/MapCacheLRU.php b/includes/libs/MapCacheLRU.php index 0b6db32ef9..b0cb078ce7 100644 --- a/includes/libs/MapCacheLRU.php +++ b/includes/libs/MapCacheLRU.php @@ -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; } /** diff --git a/tests/phpunit/includes/SampleTest.php b/tests/phpunit/includes/SampleTest.php index 258581102e..c5944d16f4 100644 --- a/tests/phpunit/includes/SampleTest.php +++ b/tests/phpunit/includes/SampleTest.php @@ -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 -- 2.20.1