From 52d7c6c383e8b9ed9c8d12f1c52f15e9e92c3c68 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 11 Feb 2021 11:13:58 +0100 Subject: [PATCH] Fix/add tests and also handle case where a json object is used --- src/Composer/Config.php | 9 +++++---- tests/Composer/Test/ConfigTest.php | 26 ++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/Composer/Config.php b/src/Composer/Config.php index 7d904d8bd..e62886122 100644 --- a/src/Composer/Config.php +++ b/src/Composer/Config.php @@ -179,12 +179,13 @@ class Config continue; } + // auto-deactivate the default packagist.org repo if it gets redefined + if (isset($repository['type'], $repository['url']) && $repository['type'] === 'composer' && preg_match('{^https?://(?:[a-z0-9-.]+\.)?packagist.org(/|$)}', $repository['url'])) { + $this->disableRepoByName('packagist.org'); + } + // store repo if (is_int($name)) { - // auto-deactivate the default packagist.org repo if it gets redefined - if (isset($repository['type'], $repository['url']) && $repository['type'] === 'composer' && preg_match('{^https?://(?:[a-z0-9-.]+\.)?packagist.org(/|$)}', $repository['url'])) { - $this->disableRepoByName('packagist.org'); - } $this->repositories[] = $repository; } else { if ($name === 'packagist') { // BC support for default "packagist" named repo diff --git a/tests/Composer/Test/ConfigTest.php b/tests/Composer/Test/ConfigTest.php index 4a4bf011b..91d4dde07 100644 --- a/tests/Composer/Test/ConfigTest.php +++ b/tests/Composer/Test/ConfigTest.php @@ -35,7 +35,7 @@ class ConfigTest extends TestCase $data = array(); $data['local config inherits system defaults'] = array( array( - 'packagist.org' => array('type' => 'composer', 'url' => 'https?://repo.packagist.org', 'allow_ssl_downgrade' => true), + 'packagist.org' => array('type' => 'composer', 'url' => 'https://repo.packagist.org'), ), array(), ); @@ -58,7 +58,7 @@ class ConfigTest extends TestCase array( 1 => array('type' => 'vcs', 'url' => 'git://github.com/composer/composer.git'), 0 => array('type' => 'pear', 'url' => 'http://pear.composer.org'), - 'packagist.org' => array('type' => 'composer', 'url' => 'https?://repo.packagist.org', 'allow_ssl_downgrade' => true), + 'packagist.org' => array('type' => 'composer', 'url' => 'https://repo.packagist.org'), ), array( array('type' => 'vcs', 'url' => 'git://github.com/composer/composer.git'), @@ -69,7 +69,7 @@ class ConfigTest extends TestCase $data['system config adds above core defaults'] = array( array( 'example.com' => array('type' => 'composer', 'url' => 'http://example.com'), - 'packagist.org' => array('type' => 'composer', 'url' => 'https?://repo.packagist.org', 'allow_ssl_downgrade' => true), + 'packagist.org' => array('type' => 'composer', 'url' => 'https://repo.packagist.org'), ), array(), array( @@ -104,9 +104,27 @@ class ConfigTest extends TestCase ), ); + $data['local config redefining packagist.org by URL override it if no named keys are used'] = array( + array( + array('type' => 'composer', 'url' => 'https://repo.packagist.org'), + ), + array( + array('type' => 'composer', 'url' => 'https://repo.packagist.org'), + ), + ); + + $data['local config redefining packagist.org by URL override it also with named keys'] = array( + array( + 'example' => array('type' => 'composer', 'url' => 'https://repo.packagist.org'), + ), + array( + 'example' => array('type' => 'composer', 'url' => 'https://repo.packagist.org'), + ), + ); + $data['incorrect local config does not cause ErrorException'] = array( array( - 'packagist.org' => array('type' => 'composer', 'url' => 'https?://repo.packagist.org', 'allow_ssl_downgrade' => true), + 'packagist.org' => array('type' => 'composer', 'url' => 'https://repo.packagist.org'), 'type' => 'vcs', 'url' => 'http://example.com', ),