1
0
Fork 0

Fix version parser regression, fixes #550

pull/498/merge
Jordi Boggiano 2012-04-09 16:00:02 +02:00
parent 68a1bc645b
commit 8654c43c62
2 changed files with 8 additions and 4 deletions

View File

@ -149,13 +149,12 @@ class VersionParser
private function parseConstraint($constraint)
{
$normalized = strtr($constraint, 'x', '*');
if ('*' === $normalized || '*.*' === $normalized || '*.*.*' === $normalized || '*.*.*.*' === $normalized) {
if (preg_match('{^[x*](\.[x*])*$}i', $constraint)) {
return array();
}
// match wildcard constraints
if (preg_match('{^(\d+)(?:\.(\d+))?(?:\.(\d+))?\.\*$}', $normalized, $matches)) {
if (preg_match('{^(\d+)(?:\.(\d+))?(?:\.(\d+))?\.[x*]$}', $constraint, $matches)) {
if (isset($matches[3])) {
$highVersion = $matches[1] . '.' . $matches[2] . '.' . $matches[3] . '.9999999';
if ($matches[3] === '0') {
@ -186,7 +185,7 @@ class VersionParser
}
// match operators constraints
if (preg_match('{^(>=?|<=?|==?)?\s*(.*)}', $normalized, $matches)) {
if (preg_match('{^(>=?|<=?|==?)?\s*(.*)}', $constraint, $matches)) {
try {
$version = $this->normalize($matches[2]);
return array(new VersionConstraint($matches[1] ?: '=', $version));

View File

@ -117,6 +117,10 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
public function simpleConstraints()
{
return array(
'match any' => array('*', new MultiConstraint(array())),
'match any/2' => array('*.*', new MultiConstraint(array())),
'match any/3' => array('*.x.*', new MultiConstraint(array())),
'match any/4' => array('x.x.x.*', new MultiConstraint(array())),
'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')),
'less/eq than' => array('<=1.2.3', new VersionConstraint('<=', '1.2.3.0')),
@ -129,6 +133,7 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
'accepts master' => array('>=dev-master', new VersionConstraint('>=', '9999999-dev')),
'accepts master/2' => array('dev-master', new VersionConstraint('=', '9999999-dev')),
'accepts arbitrary' => array('dev-feature-a', new VersionConstraint('=', 'dev-feature-a')),
'regression #550' => array('dev-some-fix', new VersionConstraint('=', 'dev-some-fix')),
'ignores aliases' => array('dev-master as 1.0.0', new VersionConstraint('=', '1.0.0.0')),
);
}