From d91fe67a80d763aff6f58bdd0d6abc3c77e088ee Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 17 Feb 2021 23:46:37 +0100 Subject: [PATCH] Remove default branch alias from versions which are numeric, fixes #9705 --- src/Composer/Package/Loader/ArrayLoader.php | 7 ++++- ...ch-default-branch-with-numeric-branch.test | 30 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/Composer/Test/Fixtures/installer/unbounded-conflict-does-not-match-default-branch-with-numeric-branch.test diff --git a/src/Composer/Package/Loader/ArrayLoader.php b/src/Composer/Package/Loader/ArrayLoader.php index f529eb625..90efb784f 100644 --- a/src/Composer/Package/Loader/ArrayLoader.php +++ b/src/Composer/Package/Loader/ArrayLoader.php @@ -375,7 +375,12 @@ class ArrayLoader implements LoaderInterface } } - if (isset($config['default-branch']) && $config['default-branch'] === true) { + + if ( + isset($config['default-branch']) + && $config['default-branch'] === true + && false === $this->versionParser->parseNumericAliasPrefix($config['version']) + ) { return VersionParser::DEFAULT_BRANCH_ALIAS; } } diff --git a/tests/Composer/Test/Fixtures/installer/unbounded-conflict-does-not-match-default-branch-with-numeric-branch.test b/tests/Composer/Test/Fixtures/installer/unbounded-conflict-does-not-match-default-branch-with-numeric-branch.test new file mode 100644 index 000000000..872738766 --- /dev/null +++ b/tests/Composer/Test/Fixtures/installer/unbounded-conflict-does-not-match-default-branch-with-numeric-branch.test @@ -0,0 +1,30 @@ +--TEST-- +Test that a conflict against >=5 does not include the default branch if it is a numeric branch. +--COMPOSER-- +{ + "repositories": [ + { + "type": "package", + "package": [ + { "name": "conflicter/pkg", "version": "1.0.0", "conflict": { "victim/pkg": ">=5", "victim/pkg2": ">=5" } }, + { "name": "victim/pkg", "version": "3.x-dev", "default-branch": true }, + { "name": "victim/pkg2", "version": "dev-foo" } + ] + } + ], + "require": { + "conflicter/pkg": "1.0.0", + "victim/pkg": "*", + "victim/pkg2": "*" + }, + "minimum-stability": "dev" +} + + +--RUN-- +update + +--EXPECT-- +Installing conflicter/pkg (1.0.0) +Installing victim/pkg (3.x-dev) +Installing victim/pkg2 (dev-foo)