From 5cd1b6d56f4b3cd89490d871633fcf71d8134e51 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Tue, 30 Jun 2015 10:57:32 +0100 Subject: [PATCH 1/2] Added documentation about -stable suffix in version range comparison. Fixes #4080. --- doc/01-basic-usage.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/doc/01-basic-usage.md b/doc/01-basic-usage.md index 3d4f2b77d..f5f45346c 100644 --- a/doc/01-basic-usage.md +++ b/doc/01-basic-usage.md @@ -94,6 +94,29 @@ so using [stability flags](04-schema.md#package-links). To change that for all packages instead of doing per dependency you can also use the [minimum-stability](04-schema.md#minimum-stability) setting. +If you are using range comparisons when selecting non-stable packages, and you +specify a numeric version number (that is, no suffix indicating alpha, beta, +rc, or stable), then both non-stable and stable versions of a particular +release number will be treated as equally valid. + + * `>=`/`<=` will accept non-stable releases as well as the stable release. + * `<`/`>` will reject non-stable releasese as well as the stable release. + +If you wish to consider only the stable release in the comparison, add the +suffix `-stable` to the version number. + +Here are some examples: + + Example | Interpretation + --------------- | -------------- +`>=1.0.0` | Any release, stable or non-, of 1.0.0 will be allowed +`>=1.0.0-stable` | Only the stable release of 1.0.0 will be allowed +`<2.0.0` | Neither release, stable or non-, of 2.0.0 will be allowed +`<2.0.0-stable` | Only the stable release of 2.0.0 will be disallowed; non-stable releases will be allowed + +Note that the packages matched by these constraints are still checked against +the `minimum-stability` setting and each package's stability flags. + ### Test version constraints You can test version constraints using [semver.mwl.be](http://semver.mwl.be). Fill in From 2cd698874ffd1af8a34b3aedaa5f629d7cb3e799 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Tue, 30 Jun 2015 11:21:49 +0100 Subject: [PATCH 2/2] Include pre-releases in >=2.3.0 comparison. Fixes #4080. This is a change to the >=2.3.0 comparison. Without this change, such a comparison will exclude pre-release versions. The rationale is that this makes the comparison more consistent with <2.3.0 (which excludes all pre-releases) and ~2.3.0 (which includes pre-releases). --- src/Composer/Package/Version/VersionParser.php | 6 ++++-- tests/Composer/Test/Package/Version/VersionParserTest.php | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Composer/Package/Version/VersionParser.php b/src/Composer/Package/Version/VersionParser.php index b5a32a448..c1cd4d229 100644 --- a/src/Composer/Package/Version/VersionParser.php +++ b/src/Composer/Package/Version/VersionParser.php @@ -443,9 +443,11 @@ class VersionParser if (!empty($stabilityModifier) && $this->parseStability($version) === 'stable') { $version .= '-' . $stabilityModifier; - } elseif ('<' === $matches[1]) { + } elseif ('<' === $matches[1] || '>=' === $matches[1]) { if (!preg_match('/-' . self::$modifierRegex . '$/', strtolower($matches[2]))) { - $version .= '-dev'; + if (substr($matches[2], 0, 4) !== 'dev-') { + $version .= '-dev'; + } } } diff --git a/tests/Composer/Test/Package/Version/VersionParserTest.php b/tests/Composer/Test/Package/Version/VersionParserTest.php index 565451811..d8f351a27 100644 --- a/tests/Composer/Test/Package/Version/VersionParserTest.php +++ b/tests/Composer/Test/Package/Version/VersionParserTest.php @@ -244,13 +244,13 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase 'greater than' => array('>1.0.0', new VersionConstraint('>', '1.0.0.0')), 'lesser than' => array('<1.2.3.4', new VersionConstraint('<', '1.2.3.4-dev')), 'less/eq than' => array('<=1.2.3', new VersionConstraint('<=', '1.2.3.0')), - 'great/eq than' => array('>=1.2.3', new VersionConstraint('>=', '1.2.3.0')), + 'great/eq than' => array('>=1.2.3', new VersionConstraint('>=', '1.2.3.0-dev')), 'equals' => array('=1.2.3', new VersionConstraint('=', '1.2.3.0')), 'double equals' => array('==1.2.3', new VersionConstraint('=', '1.2.3.0')), 'no op means eq' => array('1.2.3', new VersionConstraint('=', '1.2.3.0')), 'completes version' => array('=1.0', new VersionConstraint('=', '1.0.0.0')), 'shorthand beta' => array('1.2.3b5', new VersionConstraint('=', '1.2.3.0-beta5')), - 'accepts spaces' => array('>= 1.2.3', new VersionConstraint('>=', '1.2.3.0')), + 'accepts spaces' => array('>= 1.2.3', new VersionConstraint('>=', '1.2.3.0-dev')), 'accepts spaces/2' => array('< 1.2.3', new VersionConstraint('<', '1.2.3.0-dev')), 'accepts spaces/3' => array('> 1.2.3', new VersionConstraint('>', '1.2.3.0')), 'accepts master' => array('>=dev-master', new VersionConstraint('>=', '9999999-dev')), @@ -260,6 +260,7 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase 'regression #935' => array('dev-CAPS', new VersionConstraint('=', 'dev-CAPS')), 'ignores aliases' => array('dev-master as 1.0.0', new VersionConstraint('=', '9999999-dev')), 'lesser than override' => array('<1.2.3.4-stable', new VersionConstraint('<', '1.2.3.4')), + 'great/eq than override' => array('>=1.2.3.4-stable', new VersionConstraint('>=', '1.2.3.4')), ); }