diff --git a/src/Composer/Package/Version/VersionSelector.php b/src/Composer/Package/Version/VersionSelector.php index 138b8fabf..95c8efb4e 100644 --- a/src/Composer/Package/Version/VersionSelector.php +++ b/src/Composer/Package/Version/VersionSelector.php @@ -182,6 +182,7 @@ class VersionSelector * * For example: * * 1.2.1 -> ^1.2 + * * 1.2.1.2 -> ^1.2 * * 1.2 -> ^1.2 * * v3.2.1 -> ^3.2 * * 2.0-beta.1 -> ^2.0@beta @@ -227,7 +228,7 @@ class VersionSelector $semanticVersionParts = explode('.', $version); // check to see if we have a semver-looking version - if (count($semanticVersionParts) === 4 && Preg::isMatch('{^0\D?}', $semanticVersionParts[3])) { + if (count($semanticVersionParts) === 4 && Preg::isMatch('{^\d+\D?}', $semanticVersionParts[3])) { // remove the last parts (i.e. the patch version number and any extra) if ($semanticVersionParts[0] === '0') { unset($semanticVersionParts[3]); diff --git a/tests/Composer/Test/Package/Version/VersionSelectorTest.php b/tests/Composer/Test/Package/Version/VersionSelectorTest.php index e5d21d7a2..aec5cf86c 100644 --- a/tests/Composer/Test/Package/Version/VersionSelectorTest.php +++ b/tests/Composer/Test/Package/Version/VersionSelectorTest.php @@ -346,6 +346,9 @@ class VersionSelectorTest extends TestCase ['0.1.3', '^0.1.3'], ['0.0.3', '^0.0.3'], ['0.0.3-alpha', '^0.0.3@alpha'], + ['0.0.3.4-alpha', '^0.0.3@alpha'], + ['3.0.0.2-RC2', '^3.0@RC'], + ['1.2.1.1020402', '^1.2'], // date-based versions are not touched at all ['v20121020', 'v20121020'], ['v20121020.2', 'v20121020.2'],