From 8e61ed3507040c873a159d1031295df70e4b66de Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Tue, 29 Dec 2015 17:52:11 -0800 Subject: [PATCH] registration: Prevent loading the same thing twice Normally the registry load queue should filter out duplicates, but if people do weird things with symlinks, throw a useful error message if the double-loading makes it all the way to the processor. Bug: T121493 Change-Id: I47f5cd754e5f3c91e6b83a6d0ab542404347a421 --- includes/registration/ExtensionProcessor.php | 17 ++++++++++++++++- .../registration/ExtensionProcessorTest.php | 13 ++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/includes/registration/ExtensionProcessor.php b/includes/registration/ExtensionProcessor.php index cab889f5e5..074a962d5f 100644 --- a/includes/registration/ExtensionProcessor.php +++ b/includes/registration/ExtensionProcessor.php @@ -294,6 +294,11 @@ class ExtensionProcessor implements Processor { } } + /** + * @param string $path + * @param array $info + * @throws Exception + */ protected function extractCredits( $path, array $info ) { $credits = array( 'path' => $path, @@ -305,7 +310,17 @@ class ExtensionProcessor implements Processor { } } - $this->credits[$credits['name']] = $credits; + $name = $credits['name']; + + // If someone is loading the same thing twice, throw + // a nice error (T121493) + if ( isset( $this->credits[$name] ) ) { + $firstPath = $this->credits[$name]['path']; + $secondPath = $credits['path']; + throw new Exception( "It was attempted to load $name twice, from $firstPath and $secondPath." ); + } + + $this->credits[$name] = $credits; } /** diff --git a/tests/phpunit/includes/registration/ExtensionProcessorTest.php b/tests/phpunit/includes/registration/ExtensionProcessorTest.php index 843f576f79..590644fc06 100644 --- a/tests/phpunit/includes/registration/ExtensionProcessorTest.php +++ b/tests/phpunit/includes/registration/ExtensionProcessorTest.php @@ -118,7 +118,8 @@ class ExtensionProcessorTest extends MediaWikiTestCase { '_prefix' => 'eg', 'Bar' => 'somevalue' ), - ) + self::$default; + 'name' => 'FooBar2', + ); $processor->extractInfo( $this->dir, $info, 1 ); $processor->extractInfo( $this->dir, $info2, 1 ); $extracted = $processor->getExtractedInfo(); @@ -193,6 +194,16 @@ class ExtensionProcessorTest extends MediaWikiTestCase { } } + /** + * @covers ExtensionProcessor::extractCredits + */ + public function testExtractCredits() { + $processor = new ExtensionProcessor(); + $processor->extractInfo( $this->dir, self::$default, 1 ); + $this->setExpectedException( 'Exception' ); + $processor->extractInfo( $this->dir, self::$default, 1 ); + } + /** * @covers ExtensionProcessor::extractResourceLoaderModules * @dataProvider provideExtractResourceLoaderModules -- 2.20.1