1
0
Fork 0

Fix parsing of ~ version constraint with unstable versions, fixes #1476

pull/1486/merge
Jordi Boggiano 2013-01-13 16:36:19 +01:00
parent 71435b0b13
commit cea4c05021
2 changed files with 35 additions and 8 deletions

View File

@ -128,10 +128,7 @@ class VersionParser
if ('stable' === $matches[$index]) { if ('stable' === $matches[$index]) {
return $version; return $version;
} }
$mod = array('{^pl?$}i', '{^rc$}i'); $version .= '-' . $this->expandStability($matches[$index]) . (!empty($matches[$index+1]) ? $matches[$index+1] : '');
$modNormalized = array('patch', 'RC');
$version .= '-'.preg_replace($mod, $modNormalized, strtolower($matches[$index]))
. (!empty($matches[$index+1]) ? $matches[$index+1] : '');
} }
if (!empty($matches[$index+2])) { if (!empty($matches[$index+2])) {
@ -259,22 +256,30 @@ class VersionParser
return array(); return array();
} }
if (preg_match('{^~(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?$}', $constraint, $matches)) { if (preg_match('{^~(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?'.self::$modifierRegex.'?$}', $constraint, $matches)) {
if (isset($matches[4])) { if (isset($matches[4]) && '' !== $matches[4]) {
$highVersion = $matches[1] . '.' . $matches[2] . '.' . ($matches[3] + 1) . '.0-dev'; $highVersion = $matches[1] . '.' . $matches[2] . '.' . ($matches[3] + 1) . '.0-dev';
$lowVersion = $matches[1] . '.' . $matches[2] . '.' . $matches[3]. '.' . $matches[4]; $lowVersion = $matches[1] . '.' . $matches[2] . '.' . $matches[3]. '.' . $matches[4];
} elseif (isset($matches[3])) { } elseif (isset($matches[3]) && '' !== $matches[3]) {
$highVersion = $matches[1] . '.' . ($matches[2] + 1) . '.0.0-dev'; $highVersion = $matches[1] . '.' . ($matches[2] + 1) . '.0.0-dev';
$lowVersion = $matches[1] . '.' . $matches[2] . '.' . $matches[3]. '.0'; $lowVersion = $matches[1] . '.' . $matches[2] . '.' . $matches[3]. '.0';
} else { } else {
$highVersion = ($matches[1] + 1) . '.0.0.0-dev'; $highVersion = ($matches[1] + 1) . '.0.0.0-dev';
if (isset($matches[2])) { if (isset($matches[2]) && '' !== $matches[2]) {
$lowVersion = $matches[1] . '.' . $matches[2] . '.0.0'; $lowVersion = $matches[1] . '.' . $matches[2] . '.0.0';
} else { } else {
$lowVersion = $matches[1] . '.0.0.0'; $lowVersion = $matches[1] . '.0.0.0';
} }
} }
if (!empty($matches[5])) {
$lowVersion .= '-' . $this->expandStability($matches[5]) . (!empty($matches[6]) ? $matches[6] : '');
}
if (!empty($matches[7])) {
$lowVersion .= '-dev';
}
return array( return array(
new VersionConstraint('>=', $lowVersion), new VersionConstraint('>=', $lowVersion),
new VersionConstraint('<', $highVersion), new VersionConstraint('<', $highVersion),
@ -337,6 +342,25 @@ class VersionParser
throw new \UnexpectedValueException($message); throw new \UnexpectedValueException($message);
} }
private function expandStability($stability)
{
$stability = strtolower($stability);
switch ($stability) {
case 'a':
return 'alpha';
case 'b':
return 'beta';
case 'p':
case 'pl':
return 'patch';
case 'rc':
return 'RC';
default:
return $stability;
}
}
/** /**
* Parses a name/version pairs and returns an array of pairs + the * Parses a name/version pairs and returns an array of pairs + the
* *

View File

@ -263,6 +263,9 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
array('~1.2', new VersionConstraint('>=', '1.2.0.0'), new VersionConstraint('<', '2.0.0.0-dev')), array('~1.2', new VersionConstraint('>=', '1.2.0.0'), new VersionConstraint('<', '2.0.0.0-dev')),
array('~1.2.3', new VersionConstraint('>=', '1.2.3.0'), new VersionConstraint('<', '1.3.0.0-dev')), array('~1.2.3', new VersionConstraint('>=', '1.2.3.0'), new VersionConstraint('<', '1.3.0.0-dev')),
array('~1.2.3.4', new VersionConstraint('>=', '1.2.3.4'), new VersionConstraint('<', '1.2.4.0-dev')), array('~1.2.3.4', new VersionConstraint('>=', '1.2.3.4'), new VersionConstraint('<', '1.2.4.0-dev')),
array('~1.2-beta',new VersionConstraint('>=', '1.2.0.0-beta'), new VersionConstraint('<', '2.0.0.0-dev')),
array('~1.2-b2', new VersionConstraint('>=', '1.2.0.0-beta2'), new VersionConstraint('<', '2.0.0.0-dev')),
array('~1.2.2-dev', new VersionConstraint('>=', '1.2.2.0-dev'), new VersionConstraint('<', '1.3.0.0-dev')),
); );
} }