1
0
Fork 0

Use better semver ranges for 0.x versions, fixes #3518

pull/3522/head
Jordi Boggiano 2014-12-08 16:57:27 +00:00
parent 72a35263ec
commit 9438f3a58f
2 changed files with 18 additions and 3 deletions

View File

@ -103,10 +103,22 @@ class VersionSelector
// attempt to transform 2.1.1 to 2.1 // attempt to transform 2.1.1 to 2.1
// this allows you to upgrade through minor versions // this allows you to upgrade through minor versions
$semanticVersionParts = explode('.', $version); $semanticVersionParts = explode('.', $version);
$op = '~';
// check to see if we have a semver-looking version // check to see if we have a semver-looking version
if (count($semanticVersionParts) == 4 && preg_match('{^0\D?}', $semanticVersionParts[3])) { if (count($semanticVersionParts) == 4 && preg_match('{^0\D?}', $semanticVersionParts[3])) {
// remove the last parts (i.e. the patch version number and any extra) // remove the last parts (i.e. the patch version number and any extra)
unset($semanticVersionParts[2], $semanticVersionParts[3]); if ($semanticVersionParts[0] === '0') {
if ($semanticVersionParts[2] === '0') {
$semanticVersionParts[2] = '*';
unset($semanticVersionParts[3]);
} else {
$semanticVersionParts[3] = '*';
}
$op = '';
} else {
unset($semanticVersionParts[2], $semanticVersionParts[3]);
}
$version = implode('.', $semanticVersionParts); $version = implode('.', $semanticVersionParts);
} else { } else {
return $prettyVersion; return $prettyVersion;
@ -118,7 +130,7 @@ class VersionSelector
} }
// 2.1 -> ~2.1 // 2.1 -> ~2.1
return '~'.$version; return $op.$version;
} }
private function getParser() private function getParser()

View File

@ -98,7 +98,10 @@ class VersionSelectorTest extends \PHPUnit_Framework_TestCase
array('v1.2.1', false, 'stable', '~1.2'), array('v1.2.1', false, 'stable', '~1.2'),
array('3.1.2-pl2', false, 'stable', '~3.1'), array('3.1.2-pl2', false, 'stable', '~3.1'),
array('3.1.2-patch', false, 'stable', '~3.1'), array('3.1.2-patch', false, 'stable', '~3.1'),
// for non-stable versions, we add ~, but don't try the (1.2.1 -> 1.2) transformation array('0.1.0', false, 'stable', '0.1.*'),
array('0.1.3', false, 'stable', '0.1.3.*'),
array('0.0.3', false, 'stable', '0.0.3.*'),
array('0.0.3-alpha', false, 'alpha', '0.0.3.*@alpha'),
array('2.0-beta.1', false, 'beta', '~2.0@beta'), array('2.0-beta.1', false, 'beta', '~2.0@beta'),
array('3.1.2-alpha5', false, 'alpha', '~3.1@alpha'), array('3.1.2-alpha5', false, 'alpha', '~3.1@alpha'),
array('3.0-RC2', false, 'RC', '~3.0@RC'), array('3.0-RC2', false, 'RC', '~3.0@RC'),