From 4d413376b96b2a377f7a5206f63742743bd3f809 Mon Sep 17 00:00:00 2001 From: Cindy Cicalese Date: Sun, 23 May 2021 13:29:35 -0400 Subject: [PATCH] Fix array order for array_replace_recursive merge strategy Prior to this change, if a configuration array is defined in extension.json, array elements cannot be overridden by setting values in the corresponding configuration variable, as intended by the array_replace_recursive merge strategy. This is because the order of the arrays in the array_replace_recursive() function call need to be reversed. Bug: T283464 Change-Id: I55561232a994f745c5f3cd8394674b18c0529d13 --- includes/registration/ExtensionRegistry.php | 2 +- .../includes/registration/ExtensionRegistryTest.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/includes/registration/ExtensionRegistry.php b/includes/registration/ExtensionRegistry.php index 5fd79242f48..de4ad081a5e 100644 --- a/includes/registration/ExtensionRegistry.php +++ b/includes/registration/ExtensionRegistry.php @@ -494,7 +494,7 @@ class ExtensionRegistry { $GLOBALS[$key] = array_merge_recursive( $GLOBALS[$key], $val ); break; case 'array_replace_recursive': - $GLOBALS[$key] = array_replace_recursive( $GLOBALS[$key], $val ); + $GLOBALS[$key] = array_replace_recursive( $val, $GLOBALS[$key] ); break; case 'array_plus_2d': $GLOBALS[$key] = wfArrayPlus2d( $GLOBALS[$key], $val ); diff --git a/tests/phpunit/includes/registration/ExtensionRegistryTest.php b/tests/phpunit/includes/registration/ExtensionRegistryTest.php index 58064186f1b..a39088e3334 100644 --- a/tests/phpunit/includes/registration/ExtensionRegistryTest.php +++ b/tests/phpunit/includes/registration/ExtensionRegistryTest.php @@ -361,17 +361,17 @@ class ExtensionRegistryTest extends MediaWikiIntegrationTestCase { 'JsonZeroConfig' => [ 'namespace' => 480, 'nsName' => 'Zero', - 'isLocal' => true, + 'isLocal' => false, + 'remote' => [ + 'username' => 'foo', + ], ], ], ], [ 'mwtestJsonConfigs' => [ 'JsonZeroConfig' => [ - 'isLocal' => false, - 'remote' => [ - 'username' => 'foo', - ], + 'isLocal' => true, ], ExtensionRegistry::MERGE_STRATEGY => 'array_replace_recursive', ],