Use better semver ranges for 0.x versions, fixes #3518
parent
72a35263ec
commit
9438f3a58f
|
@ -103,10 +103,22 @@ class VersionSelector
|
|||
// attempt to transform 2.1.1 to 2.1
|
||||
// this allows you to upgrade through minor versions
|
||||
$semanticVersionParts = explode('.', $version);
|
||||
$op = '~';
|
||||
|
||||
// check to see if we have a semver-looking version
|
||||
if (count($semanticVersionParts) == 4 && preg_match('{^0\D?}', $semanticVersionParts[3])) {
|
||||
// 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);
|
||||
} else {
|
||||
return $prettyVersion;
|
||||
|
@ -118,7 +130,7 @@ class VersionSelector
|
|||
}
|
||||
|
||||
// 2.1 -> ~2.1
|
||||
return '~'.$version;
|
||||
return $op.$version;
|
||||
}
|
||||
|
||||
private function getParser()
|
||||
|
|
|
@ -98,7 +98,10 @@ class VersionSelectorTest extends \PHPUnit_Framework_TestCase
|
|||
array('v1.2.1', false, 'stable', '~1.2'),
|
||||
array('3.1.2-pl2', 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('3.1.2-alpha5', false, 'alpha', '~3.1@alpha'),
|
||||
array('3.0-RC2', false, 'RC', '~3.0@RC'),
|
||||
|
|
Loading…
Reference in New Issue