1
0
Fork 0

Allow .x in version constraints as alias for .*

pull/426/merge
Jordi Boggiano 2012-04-08 17:02:29 +02:00
parent 96c9bf80cc
commit f604ca5762
2 changed files with 6 additions and 5 deletions

View File

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

View File

@ -154,8 +154,8 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
array('2.*', new VersionConstraint('>', '1.9999999.9999999.9999999'), new VersionConstraint('<', '2.9999999.9999999.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('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.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.2.x', 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.10.x', 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('2.1.3.*', new VersionConstraint('>', '2.1.2.9999999'), new VersionConstraint('<', '2.1.3.9999999')),
array('0.*', null, new VersionConstraint('<', '0.9999999.9999999.9999999')), array('0.*', null, new VersionConstraint('<', '0.9999999.9999999.9999999')),
); );