Browse files

Allow parsing of stability modifiers combined with multi-constraints

  • Loading branch information...
1 parent b3077bc commit 62bb5b339b657cafccdee72a1a3e92490eb14a35 @Seldaek Seldaek committed Oct 5, 2012
View
11 src/Composer/Package/Version/VersionParser.php
@@ -234,6 +234,13 @@ public function parseConstraints($constraints)
private function parseConstraint($constraint)
{
+ if (preg_match('{^([^,\s]+?)@('.implode('|', array_keys(BasePackage::$stabilities)).')$}i', $constraint, $match)) {
+ $constraint = $match[1];
+ if ($match[2] !== 'stable') {
+ $stabilityModifier = $match[2];
+ }
+ }
+
if (preg_match('{^[x*](\.[x*])*$}i', $constraint)) {
return array();
}
@@ -274,6 +281,10 @@ private function parseConstraint($constraint)
try {
$version = $this->normalize($matches[2]);
+ if (!empty($stabilityModifier) && $this->parseStability($version) === 'stable') {
+ $version .= '-' . $stabilityModifier;
+ }
+
return array(new VersionConstraint($matches[1] ?: '=', $version));
} catch (\Exception $e) {}
}
View
9 tests/Composer/Test/Package/Version/VersionParserTest.php
@@ -249,6 +249,15 @@ public function testParseConstraintsMulti()
$this->assertSame((string) $multi, (string) $parser->parseConstraints('>2.0,<=3.0'));
}
+ public function testParseConstraintsMultiWithStabilities()
+ {
+ $parser = new VersionParser;
+ $first = new VersionConstraint('>', '2.0.0.0');
+ $second = new VersionConstraint('<=', '3.0.0.0-dev');
+ $multi = new MultiConstraint(array($first, $second));
+ $this->assertSame((string) $multi, (string) $parser->parseConstraints('>2.0@stable,<=3.0@dev'));
+ }
+
/**
* @dataProvider failingConstraints
* @expectedException UnexpectedValueException

1 comment on commit 62bb5b3

@stloyd

👍

Please sign in to comment.