Skip to content

Commit be71bf0

Browse files
committed
Fix support for versions with 4 components in VersionSelector, fixes #11716
1 parent 12ed217 commit be71bf0

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/Composer/Package/Version/VersionSelector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ public function findBestCandidate(string $packageName, ?string $targetPackageVer
182182
*
183183
* For example:
184184
* * 1.2.1 -> ^1.2
185+
* * 1.2.1.2 -> ^1.2
185186
* * 1.2 -> ^1.2
186187
* * v3.2.1 -> ^3.2
187188
* * 2.0-beta.1 -> ^2.0@beta
@@ -227,7 +228,7 @@ private function transformVersion(string $version, string $prettyVersion, string
227228
$semanticVersionParts = explode('.', $version);
228229

229230
// check to see if we have a semver-looking version
230-
if (count($semanticVersionParts) === 4 && Preg::isMatch('{^0\D?}', $semanticVersionParts[3])) {
231+
if (count($semanticVersionParts) === 4 && Preg::isMatch('{^\d+\D?}', $semanticVersionParts[3])) {
231232
// remove the last parts (i.e. the patch version number and any extra)
232233
if ($semanticVersionParts[0] === '0') {
233234
unset($semanticVersionParts[3]);

tests/Composer/Test/Package/Version/VersionSelectorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,9 @@ public static function provideRecommendedRequireVersionPackages(): array
346346
['0.1.3', '^0.1.3'],
347347
['0.0.3', '^0.0.3'],
348348
['0.0.3-alpha', '^0.0.3@alpha'],
349+
['0.0.3.4-alpha', '^0.0.3@alpha'],
350+
['3.0.0.2-RC2', '^3.0@RC'],
351+
['1.2.1.1020402', '^1.2'],
349352
// date-based versions are not touched at all
350353
['v20121020', 'v20121020'],
351354
['v20121020.2', 'v20121020.2'],

0 commit comments

Comments
 (0)