From 04362aa6130163c369f596be83b4233d21b112c1 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Tue, 16 Feb 2016 20:39:34 +0000 Subject: [PATCH] registration: Avoid double slashes in localBasePath Noticed it in APC usage for ResourceLoader that various keys from FileContentsHasher contain double slashes. All from extensions that use the `"localBasePath": ""` trick in extension.json (e.g. Citoid). Change-Id: I5bac1e2e05e063aa7ff251ce7ffaa965a3451db9 --- includes/registration/ExtensionProcessor.php | 14 ++++++++++++-- .../registration/ExtensionProcessorTest.php | 4 ++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/includes/registration/ExtensionProcessor.php b/includes/registration/ExtensionProcessor.php index 2318c87b03..fe9304fb61 100644 --- a/includes/registration/ExtensionProcessor.php +++ b/includes/registration/ExtensionProcessor.php @@ -253,14 +253,24 @@ class ExtensionProcessor implements Processor { ? $info['ResourceFileModulePaths'] : false; if ( isset( $defaultPaths['localBasePath'] ) ) { - $defaultPaths['localBasePath'] = "$dir/{$defaultPaths['localBasePath']}"; + if ( $defaultPaths['localBasePath'] === '' ) { + // Avoid double slashes (e.g. /extensions/Example//path) + $defaultPaths['localBasePath'] = $dir; + } else { + $defaultPaths['localBasePath'] = "$dir/{$defaultPaths['localBasePath']}"; + } } foreach ( [ 'ResourceModules', 'ResourceModuleSkinStyles' ] as $setting ) { if ( isset( $info[$setting] ) ) { foreach ( $info[$setting] as $name => $data ) { if ( isset( $data['localBasePath'] ) ) { - $data['localBasePath'] = "$dir/{$data['localBasePath']}"; + if ( $data['localBasePath'] === '' ) { + // Avoid double slashes (e.g. /extensions/Example//path) + $data['localBasePath'] = $dir; + } else { + $data['localBasePath'] = "$dir/{$data['localBasePath']}"; + } } if ( $defaultPaths ) { $data += $defaultPaths; diff --git a/tests/phpunit/includes/registration/ExtensionProcessorTest.php b/tests/phpunit/includes/registration/ExtensionProcessorTest.php index 7f84e33ad5..35aca48f44 100644 --- a/tests/phpunit/includes/registration/ExtensionProcessorTest.php +++ b/tests/phpunit/includes/registration/ExtensionProcessorTest.php @@ -218,7 +218,7 @@ class ExtensionProcessorTest extends MediaWikiTestCase { } public static function provideExtractResourceLoaderModules() { - $dir = __DIR__ . '/FooBar/'; + $dir = __DIR__ . '/FooBar'; return [ // Generic module with localBasePath/remoteExtPath specified [ @@ -285,7 +285,7 @@ class ExtensionProcessorTest extends MediaWikiTestCase { ], 'test.bar' => [ 'styles' => 'bar.js', - 'localBasePath' => $dir . 'subdir', + 'localBasePath' => "$dir/subdir", 'remoteExtPath' => 'FooBar/subdir', ], 'test.class' => [ -- 2.20.1