From 8a8c50c3a6467a05dd6363342c65c1d789922683 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 13 Sep 2022 14:50:27 +0200 Subject: [PATCH] Fix handling of upper-bound platform req ignores to not act on conflicts (#11037) * Fix handling of upper-bound platform req ignores to not act on conflicts, fixes #11020 * Optimization --- src/Composer/DependencyResolver/RuleSetGenerator.php | 2 +- .../IgnoreListPlatformRequirementFilter.php | 5 +++-- ...gnore-platform-package-requirement-list-upper-bounds.test | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Composer/DependencyResolver/RuleSetGenerator.php b/src/Composer/DependencyResolver/RuleSetGenerator.php index 9164c333a..bd4b197d1 100644 --- a/src/Composer/DependencyResolver/RuleSetGenerator.php +++ b/src/Composer/DependencyResolver/RuleSetGenerator.php @@ -233,7 +233,7 @@ class RuleSetGenerator if ($platformRequirementFilter->isIgnored($link->getTarget())) { continue; } elseif ($platformRequirementFilter instanceof IgnoreListPlatformRequirementFilter) { - $constraint = $platformRequirementFilter->filterConstraint($link->getTarget(), $constraint); + $constraint = $platformRequirementFilter->filterConstraint($link->getTarget(), $constraint, false); } $conflicts = $this->pool->whatProvides($link->getTarget(), $constraint); diff --git a/src/Composer/Filter/PlatformRequirementFilter/IgnoreListPlatformRequirementFilter.php b/src/Composer/Filter/PlatformRequirementFilter/IgnoreListPlatformRequirementFilter.php index d6d95a287..a7ce1aaaf 100644 --- a/src/Composer/Filter/PlatformRequirementFilter/IgnoreListPlatformRequirementFilter.php +++ b/src/Composer/Filter/PlatformRequirementFilter/IgnoreListPlatformRequirementFilter.php @@ -57,14 +57,15 @@ final class IgnoreListPlatformRequirementFilter implements PlatformRequirementFi /** * @param string $req * @return ConstraintInterface + * @param bool $allowUpperBoundOverride For conflicts we do not want the upper bound to be skipped */ - public function filterConstraint($req, ConstraintInterface $constraint) + public function filterConstraint($req, ConstraintInterface $constraint, $allowUpperBoundOverride = true) { if (!PlatformRepository::isPlatformPackage($req)) { return $constraint; } - if (!Preg::isMatch($this->ignoreUpperBoundRegex, $req)) { + if (!$allowUpperBoundOverride || !Preg::isMatch($this->ignoreUpperBoundRegex, $req)) { return $constraint; } diff --git a/tests/Composer/Test/Fixtures/installer/update-ignore-platform-package-requirement-list-upper-bounds.test b/tests/Composer/Test/Fixtures/installer/update-ignore-platform-package-requirement-list-upper-bounds.test index 0c7e776de..62d8fbb4b 100644 --- a/tests/Composer/Test/Fixtures/installer/update-ignore-platform-package-requirement-list-upper-bounds.test +++ b/tests/Composer/Test/Fixtures/installer/update-ignore-platform-package-requirement-list-upper-bounds.test @@ -7,13 +7,15 @@ Update with ignore-platform-req list ignoring upper bound of a dependency "type": "package", "package": [ { "name": "a/a", "version": "1.0.1", "require": { "ext-foo-bar": "3.*" } }, - { "name": "b/b", "version": "1.0.1", "require": { "ext-foo-bar": "10.*" } } + { "name": "b/b", "version": "1.0.1", "require": { "ext-foo-bar": "10.*" } }, + { "name": "c/c", "version": "1.0.1", "conflict": { "ext-foo-bar": "4.0.0 - 4.0.2", "php": "3.0.*" } } ] } ], "require": { "a/a": "1.0.*", "b/b": "1.0.*", + "c/c": "1.0.*", "php": "^4.3", "ext-foo-baz": "9.0.0" },