From 7a09e05560652f24a2d14e5966fa2f118f499e3e Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Wed, 25 Oct 2023 17:04:52 +0100 Subject: [PATCH] Bump wildcard constraints to >=current (#11694) --- src/Composer/Package/Version/VersionBumper.php | 4 +++- tests/Composer/Test/Package/Version/VersionBumperTest.php | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Composer/Package/Version/VersionBumper.php b/src/Composer/Package/Version/VersionBumper.php index 690dfbeed..aa86d66de 100644 --- a/src/Composer/Package/Version/VersionBumper.php +++ b/src/Composer/Package/Version/VersionBumper.php @@ -40,6 +40,7 @@ class VersionBumper * * ^3@dev + 3.2.99999-dev -> ^3.2@dev * * ~2 + 2.0-beta.1 -> ~2 * * dev-master + dev-master -> dev-master + * * * + 1.2.3 -> >=1.2.3 */ public function bumpRequirement(ConstraintInterface $constraint, PackageInterface $package): string { @@ -86,6 +87,7 @@ class VersionBumper | ~'.$major.'(?:\.\d+){0,2} # e.g. ~2 or ~2.2 or ~2.2.2 but no more | '.$major.'(?:\.[*x])+ # e.g. 2.* or 2.*.* or 2.x.x.x etc | >=\d(?:\.\d+)* # e.g. >=2 or >=1.2 etc + | \* # full wildcard ) (?=,|$|\ |\||@) # trailing separator }x'; @@ -99,7 +101,7 @@ class VersionBumper } if (str_starts_with($match[0], '~') && substr_count($match[0], '.') === 2) { $replacement = '~'.$versionWithoutSuffix.$suffix; - } elseif (str_starts_with($match[0], '>=')) { + } elseif ($match[0] === '*' || str_starts_with($match[0], '>=')) { $replacement = '>='.$versionWithoutSuffix.$suffix; } else { $replacement = $newPrettyConstraint.$suffix; diff --git a/tests/Composer/Test/Package/Version/VersionBumperTest.php b/tests/Composer/Test/Package/Version/VersionBumperTest.php index b8f07844f..4d0b610c0 100644 --- a/tests/Composer/Test/Package/Version/VersionBumperTest.php +++ b/tests/Composer/Test/Package/Version/VersionBumperTest.php @@ -67,5 +67,6 @@ class VersionBumperTest extends TestCase yield 'leave extra-only-tilde alone' => ['~2.2.3.1', '2.2.4.5', '~2.2.3.1']; yield 'upgrade bigger-or-eq to latest' => ['>=3.0', '3.4.5', '>=3.4.5']; yield 'leave bigger-than untouched' => ['>2.2.3', '2.2.6', '>2.2.3']; + yield 'upgrade full wildcard to bigger-or-eq' => ['*', '1.2.3', '>=1.2.3']; } }