Skip to content

Commit

Permalink
Fix support for versions with 4 components in VersionSelector, fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Jan 8, 2024
1 parent 12ed217 commit be71bf0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Composer/Package/Version/VersionSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ public function findBestCandidate(string $packageName, ?string $targetPackageVer
*
* 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
Expand Down Expand Up @@ -227,7 +228,7 @@ private function transformVersion(string $version, string $prettyVersion, string
$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]);
Expand Down
3 changes: 3 additions & 0 deletions tests/Composer/Test/Package/Version/VersionSelectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ public static function provideRecommendedRequireVersionPackages(): array
['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'],
Expand Down

0 comments on commit be71bf0

Please sign in to comment.