From 22858e81efeb197d8a19e2f20f8cd6c22a98c9b9 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 23 Nov 2011 16:41:27 +0100 Subject: [PATCH] Fix .* version constraints parsing to include nonstable versions --- .../Package/Version/VersionParser.php | 20 +++++++++++++++---- .../Package/Version/VersionParserTest.php | 19 +++++++++++------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/Composer/Package/Version/VersionParser.php b/src/Composer/Package/Version/VersionParser.php index 54d3ed1a6..80fb45c3c 100644 --- a/src/Composer/Package/Version/VersionParser.php +++ b/src/Composer/Package/Version/VersionParser.php @@ -135,18 +135,30 @@ class VersionParser // match wildcard constraints if (preg_match('{^(\d+)(?:\.(\d+))?(?:\.(\d+))?\.\*$}', $constraint, $matches)) { if (isset($matches[3])) { - $lowVersion = $matches[1] . '.' . $matches[2] . '.' . $matches[3] . '.0'; $highVersion = $matches[1] . '.' . $matches[2] . '.' . $matches[3] . '.9999999'; + if ($matches[3] === '0') { + $lowVersion = $matches[1] . '.' . ($matches[2] - 1) . '.9999999.9999999'; + } else { + $lowVersion = $matches[1] . '.' . $matches[2] . '.' . ($matches[3] - 1). '.9999999'; + } } elseif (isset($matches[2])) { - $lowVersion = $matches[1] . '.' . $matches[2] . '.0.0'; $highVersion = $matches[1] . '.' . $matches[2] . '.9999999.9999999'; + if ($matches[2] === '0') { + $lowVersion = ($matches[1] - 1) . '.9999999.9999999.9999999'; + } else { + $lowVersion = $matches[1] . '.' . ($matches[2] - 1) . '.9999999.9999999'; + } } else { - $lowVersion = $matches[1] . '.0.0.0'; $highVersion = $matches[1] . '.9999999.9999999.9999999'; + if ($matches[1] === '0') { + return array(new VersionConstraint('<', $highVersion)); + } else { + $lowVersion = ($matches[1] - 1) . '.9999999.9999999.9999999'; + } } return array( - new VersionConstraint('>=', $lowVersion), + new VersionConstraint('>', $lowVersion), new VersionConstraint('<', $highVersion), ); } diff --git a/tests/Composer/Test/Package/Version/VersionParserTest.php b/tests/Composer/Test/Package/Version/VersionParserTest.php index b3c8e24d2..faca00dc9 100644 --- a/tests/Composer/Test/Package/Version/VersionParserTest.php +++ b/tests/Composer/Test/Package/Version/VersionParserTest.php @@ -132,7 +132,11 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase public function testParseConstraintsWildcard($input, $min, $max) { $parser = new VersionParser; - $expected = new MultiConstraint(array($min, $max)); + if ($min) { + $expected = new MultiConstraint(array($min, $max)); + } else { + $expected = $max; + } $this->assertSame((string) $expected, (string) $parser->parseConstraints($input)); } @@ -140,12 +144,13 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase public function wildcardConstraints() { return array( - array('2.*', new VersionConstraint('>=', '2.0.0.0'), new VersionConstraint('<', '2.9999999.9999999.9999999')), - array('20.*', new VersionConstraint('>=', '20.0.0.0'), new VersionConstraint('<', '20.9999999.9999999.9999999')), - array('2.0.*', new VersionConstraint('>=', '2.0.0.0'), new VersionConstraint('<', '2.0.9999999.9999999')), - array('2.2.*', new VersionConstraint('>=', '2.2.0.0'), new VersionConstraint('<', '2.2.9999999.9999999')), - array('2.10.*', new VersionConstraint('>=', '2.10.0.0'), new VersionConstraint('<', '2.10.9999999.9999999')), - array('2.1.3.*', new VersionConstraint('>=', '2.1.3.0'), new VersionConstraint('<', '2.1.3.9999999')), + array('2.*', new VersionConstraint('>', '1.9999999.9999999.9999999'), new VersionConstraint('<', '2.9999999.9999999.9999999')), + array('20.*', new VersionConstraint('>', '19.9999999.9999999.9999999'), new VersionConstraint('<', '20.9999999.9999999.9999999')), + array('2.0.*', new VersionConstraint('>', '1.9999999.9999999.9999999'), new VersionConstraint('<', '2.0.9999999.9999999')), + array('2.2.*', new VersionConstraint('>', '2.1.9999999.9999999'), new VersionConstraint('<', '2.2.9999999.9999999')), + array('2.10.*', new VersionConstraint('>', '2.9.9999999.9999999'), new VersionConstraint('<', '2.10.9999999.9999999')), + array('2.1.3.*', new VersionConstraint('>', '2.1.2.9999999'), new VersionConstraint('<', '2.1.3.9999999')), + array('0.*', null, new VersionConstraint('<', '0.9999999.9999999.9999999')), ); }