From 7aeb1b0c413c0a8131b378aaf2aa9b3f29a03c56 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 17 Mar 2017 22:09:51 +0100 Subject: [PATCH] Fix conversion of repo format in config command, fixes #6245, closes #6271 --- src/Composer/Config/JsonConfigSource.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Composer/Config/JsonConfigSource.php b/src/Composer/Config/JsonConfigSource.php index cbfb2292c..68de49ab3 100644 --- a/src/Composer/Config/JsonConfigSource.php +++ b/src/Composer/Config/JsonConfigSource.php @@ -60,6 +60,21 @@ class JsonConfigSource implements ConfigSourceInterface public function addRepository($name, $config) { $this->manipulateJson('addRepository', $name, $config, function (&$config, $repo, $repoConfig) { + // if converting from an array format to hashmap format, and there is a {"packagist.org":false} repo, we have + // to convert it to "packagist.org": false key on the hashmap otherwise it fails schema validation + if (isset($config['repositories'])) { + foreach ($config['repositories'] as $index => $val) { + if ($index === $repo) { + continue; + } + if (is_numeric($index) && ($val === array('packagist' => false) || $val === array('packagist.org' => false))) { + unset($config['repositories'][$index]); + $config['repositories']['packagist.org'] = false; + break; + } + } + } + $config['repositories'][$repo] = $repoConfig; }); }