From 91b7b0ff3bfa85b784a0aa173a66254421644c1a Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 21 Mar 2023 11:07:57 +0100 Subject: [PATCH 1/5] Fixed querying of default config values, and fix source display for them, and fix bools to show as bools, fixes #11302 --- src/Composer/Command/ConfigCommand.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Composer/Command/ConfigCommand.php b/src/Composer/Command/ConfigCommand.php index d7f4ad78a..3d5fb11d3 100644 --- a/src/Composer/Command/ConfigCommand.php +++ b/src/Composer/Command/ConfigCommand.php @@ -274,8 +274,21 @@ EOT // show the value if no value is provided if ([] === $input->getArgument('setting-value') && !$input->getOption('unset')) { $properties = self::CONFIGURABLE_PACKAGE_PROPERTIES; + $propertiesDefaults = [ + 'type' => 'library', + 'description' => '', + 'homepage' => '', + 'minimum-stability' => 'stable', + 'prefer-stable' => false, + 'keywords' => [], + 'license' => [], + 'suggest' => [], + 'extra' => [], + ]; $rawData = $this->configFile->read(); $data = $this->config->all(); + $source = $this->config->getSourceOfValue($settingKey); + if (Preg::isMatch('/^repos?(?:itories)?(?:\.(.+))?/', $settingKey, $matches)) { if (!isset($matches[1]) || $matches[1] === '') { $value = $data['repositories'] ?? []; @@ -313,17 +326,21 @@ EOT $value = $this->config->get($settingKey, $input->getOption('absolute') ? 0 : Config::RELATIVE_PATHS); } elseif (isset($rawData[$settingKey]) && in_array($settingKey, $properties, true)) { $value = $rawData[$settingKey]; + $source = $this->configFile->getPath(); + } elseif (isset($propertiesDefaults[$settingKey])) { + $value = $propertiesDefaults[$settingKey]; + $source = 'defaults'; } else { throw new \RuntimeException($settingKey.' is not defined'); } - if (is_array($value)) { + if (is_array($value) || is_bool($value)) { $value = JsonFile::encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); } $sourceOfConfigValue = ''; if ($input->getOption('source')) { - $sourceOfConfigValue = ' (' . $this->config->getSourceOfValue($settingKey) . ')'; + $sourceOfConfigValue = ' (' . $source . ')'; } $this->getIO()->write($value . $sourceOfConfigValue, true, IOInterface::QUIET); From 8b0a185d5da328d16b1f46006f0c1523ce0dc539 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 21 Mar 2023 11:17:55 +0100 Subject: [PATCH 2/5] Fixed display of empty objects showing [] instead of {} in config command, fixes #11302 --- src/Composer/Command/ConfigCommand.php | 12 +++++++++++- src/Composer/PHPStan/ConfigReturnTypeExtension.php | 2 +- tests/Composer/Test/Json/ComposerSchemaTest.php | 3 ++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Composer/Command/ConfigCommand.php b/src/Composer/Command/ConfigCommand.php index 3d5fb11d3..bef163b3d 100644 --- a/src/Composer/Command/ConfigCommand.php +++ b/src/Composer/Command/ConfigCommand.php @@ -324,6 +324,16 @@ EOT $value = $data; } elseif (isset($data['config'][$settingKey])) { $value = $this->config->get($settingKey, $input->getOption('absolute') ? 0 : Config::RELATIVE_PATHS); + // ensure we get {} output for properties which are objects + if ($value === []) { + $schema = JsonFile::parseJson((string) file_get_contents(JsonFile::COMPOSER_SCHEMA_PATH)); + if ( + isset($schema['properties']['config']['properties'][$settingKey]['type']) + && in_array('object', (array) $schema['properties']['config']['properties'][$settingKey]['type'], true) + ) { + $value = new \stdClass; + } + } } elseif (isset($rawData[$settingKey]) && in_array($settingKey, $properties, true)) { $value = $rawData[$settingKey]; $source = $this->configFile->getPath(); @@ -334,7 +344,7 @@ EOT throw new \RuntimeException($settingKey.' is not defined'); } - if (is_array($value) || is_bool($value)) { + if (is_array($value) || is_object($value) || is_bool($value)) { $value = JsonFile::encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); } diff --git a/src/Composer/PHPStan/ConfigReturnTypeExtension.php b/src/Composer/PHPStan/ConfigReturnTypeExtension.php index a3081872e..46d373509 100644 --- a/src/Composer/PHPStan/ConfigReturnTypeExtension.php +++ b/src/Composer/PHPStan/ConfigReturnTypeExtension.php @@ -39,7 +39,7 @@ final class ConfigReturnTypeExtension implements DynamicMethodReturnTypeExtensio public function __construct() { - $schema = JsonFile::parseJson((string) file_get_contents(__DIR__.'/../../../res/composer-schema.json')); + $schema = JsonFile::parseJson((string) file_get_contents(JsonFile::COMPOSER_SCHEMA_PATH)); /** * @var string $prop */ diff --git a/tests/Composer/Test/Json/ComposerSchemaTest.php b/tests/Composer/Test/Json/ComposerSchemaTest.php index c964a170c..9a6735091 100644 --- a/tests/Composer/Test/Json/ComposerSchemaTest.php +++ b/tests/Composer/Test/Json/ComposerSchemaTest.php @@ -12,6 +12,7 @@ namespace Composer\Test\Json; +use Composer\Json\JsonFile; use JsonSchema\Validator; use Composer\Test\TestCase; @@ -96,7 +97,7 @@ class ComposerSchemaTest extends TestCase private function check(string $json) { $validator = new Validator(); - $validator->check(json_decode($json), (object) ['$ref' => 'file://' . __DIR__ . '/../../../../res/composer-schema.json']); + $validator->check(json_decode($json), (object) ['$ref' => 'file://' . JsonFile::COMPOSER_SCHEMA_PATH]); if (!$validator->isValid()) { $errors = $validator->getErrors(); From 62ec143393b6db94f140d42d1f8bd6bc6f4330ae Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 21 Mar 2023 11:49:57 +0100 Subject: [PATCH 3/5] Update changelog --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5405513ad..5a48af7ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +### [2.5.5] 2023-03-21 + + * Fixed basic auth failures resulting in infinite retry loop (#11320) + * Fixed GitHub rate limit reporting (#11366) + * Fixed InstalledVersions error in Composer 1 compatibility edge case (#11304) + * Fixed issue displaying solver problems with branch names containing `%` signs (#11359) + * Fixed race condition in cache validity detection when running Composer highly concurrently (#11375) + * Fixed various minor config command issues (#11353, #11302) + ### [2.5.4] 2023-02-15 * Fixed extra.plugin-optional support in PluginInstaller when doing pre-install checks (#11318) @@ -1699,6 +1708,7 @@ * Initial release +[2.5.5]: https://github.com/composer/composer/compare/2.5.4...2.5.5 [2.5.4]: https://github.com/composer/composer/compare/2.5.3...2.5.4 [2.5.3]: https://github.com/composer/composer/compare/2.5.2...2.5.3 [2.5.2]: https://github.com/composer/composer/compare/2.5.1...2.5.2 From c7cffaad16a60636a776017eac5bd8cd0095c32f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 21 Mar 2023 11:50:05 +0100 Subject: [PATCH 4/5] Release 2.5.5 --- src/Composer/Composer.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Composer/Composer.php b/src/Composer/Composer.php index 8a870cc47..195e9e43c 100644 --- a/src/Composer/Composer.php +++ b/src/Composer/Composer.php @@ -51,10 +51,10 @@ class Composer extends PartialComposer * * @see getVersion() */ - public const VERSION = '@package_version@'; - public const BRANCH_ALIAS_VERSION = '@package_branch_alias_version@'; - public const RELEASE_DATE = '@release_date@'; - public const SOURCE_VERSION = '2.5.999-dev+source'; + public const VERSION = '2.5.5'; + public const BRANCH_ALIAS_VERSION = ''; + public const RELEASE_DATE = '2023-03-21 11:50:05'; + public const SOURCE_VERSION = ''; /** * Version number of the internal composer-runtime-api package From 766628a8d48a704db1e5c9587cc3e8068a997d4d Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 21 Mar 2023 11:50:06 +0100 Subject: [PATCH 5/5] Reverting release version changes --- src/Composer/Composer.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Composer/Composer.php b/src/Composer/Composer.php index 195e9e43c..8a870cc47 100644 --- a/src/Composer/Composer.php +++ b/src/Composer/Composer.php @@ -51,10 +51,10 @@ class Composer extends PartialComposer * * @see getVersion() */ - public const VERSION = '2.5.5'; - public const BRANCH_ALIAS_VERSION = ''; - public const RELEASE_DATE = '2023-03-21 11:50:05'; - public const SOURCE_VERSION = ''; + public const VERSION = '@package_version@'; + public const BRANCH_ALIAS_VERSION = '@package_branch_alias_version@'; + public const RELEASE_DATE = '@release_date@'; + public const SOURCE_VERSION = '2.5.999-dev+source'; /** * Version number of the internal composer-runtime-api package