From 82349bcb2a761ec20e72a63055b6df9b6067f86d Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 27 Oct 2015 14:59:48 +0000 Subject: [PATCH] Fix support for extracting stability flags in multi-constraints, fixes #4440 --- .../Package/Loader/RootPackageLoader.php | 31 ++++++++++++++----- .../Package/Loader/RootPackageLoaderTest.php | 4 +++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/Composer/Package/Loader/RootPackageLoader.php b/src/Composer/Package/Loader/RootPackageLoader.php index 1266346db..06c70e8b0 100644 --- a/src/Composer/Package/Loader/RootPackageLoader.php +++ b/src/Composer/Package/Loader/RootPackageLoader.php @@ -144,16 +144,33 @@ class RootPackageLoader extends ArrayLoader $stabilities = BasePackage::$stabilities; $minimumStability = $stabilities[$minimumStability]; foreach ($requires as $reqName => $reqVersion) { - // parse explicit stability flags to the most unstable - if (preg_match('{^[^@]*?@('.implode('|', array_keys($stabilities)).')$}i', $reqVersion, $match)) { - $name = strtolower($reqName); - $stability = $stabilities[VersionParser::normalizeStability($match[1])]; + $constraints = array(); - if (isset($stabilityFlags[$name]) && $stabilityFlags[$name] > $stability) { - continue; + // extract all sub-constraints in case it is an OR/AND multi-constraint + $orSplit = preg_split('{\s*\|\|?\s*}', trim($reqVersion)); + foreach ($orSplit as $constraint) { + $andSplit = preg_split('{(?< ,]) *(? $stability) { + continue; + } + $stabilityFlags[$name] = $stability; + $match = true; + } + } + + if ($match) { continue; } diff --git a/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php b/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php index 218d6e5ff..b03d2c581 100644 --- a/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php +++ b/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php @@ -42,6 +42,8 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase 'bar/baz' => '1.0.x-dev as 1.2.0', 'qux/quux' => '1.0.*@rc', 'zux/complex' => '~1.0,>=1.0.2@dev', + 'or/op' => '^2.0@dev || ^2.0@dev', + 'multi/lowest-wins' => '^2.0@rc || >=3.0@dev , ~3.5@alpha', ), 'minimum-stability' => 'alpha', )); @@ -51,6 +53,8 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase 'bar/baz' => BasePackage::STABILITY_DEV, 'qux/quux' => BasePackage::STABILITY_RC, 'zux/complex' => BasePackage::STABILITY_DEV, + 'or/op' => BasePackage::STABILITY_DEV, + 'multi/lowest-wins' => BasePackage::STABILITY_DEV, ), $package->getStabilityFlags()); }