From 4a209b7d3dc57130c10647277768f14ba53da9db Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 19 Dec 2023 17:17:32 +0100 Subject: [PATCH] Fix bump command not bumping versions with a v prefix e.g. ^v2.4, fixes #11723 (#11764) --- src/Composer/Package/Version/VersionBumper.php | 8 ++++---- tests/Composer/Test/Command/BumpCommandTest.php | 2 +- tests/Composer/Test/Package/Version/VersionBumperTest.php | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Composer/Package/Version/VersionBumper.php b/src/Composer/Package/Version/VersionBumper.php index 690dfbeed..9292b6cdb 100644 --- a/src/Composer/Package/Version/VersionBumper.php +++ b/src/Composer/Package/Version/VersionBumper.php @@ -82,10 +82,10 @@ class VersionBumper $pattern = '{ (?<=,|\ |\||^) # leading separator (?P - \^'.$major.'(?:\.\d+)* # e.g. ^2.anything - | ~'.$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 + \^v?'.$major.'(?:\.\d+)* # e.g. ^2.anything + | ~v?'.$major.'(?:\.\d+){0,2} # e.g. ~2 or ~2.2 or ~2.2.2 but no more + | v?'.$major.'(?:\.[*x])+ # e.g. 2.* or 2.*.* or 2.x.x.x etc + | >=v?\d(?:\.\d+)* # e.g. >=2 or >=1.2 etc ) (?=,|$|\ |\||@) # trailing separator }x'; diff --git a/tests/Composer/Test/Command/BumpCommandTest.php b/tests/Composer/Test/Command/BumpCommandTest.php index 8489ef017..383aaf90c 100644 --- a/tests/Composer/Test/Command/BumpCommandTest.php +++ b/tests/Composer/Test/Command/BumpCommandTest.php @@ -76,7 +76,7 @@ class BumpCommandTest extends TestCase yield 'bump all by default' => [ [ 'require' => [ - 'first/pkg' => '^2.0', + 'first/pkg' => '^v2.0', 'second/pkg' => '3.*', ], 'require-dev' => [ diff --git a/tests/Composer/Test/Package/Version/VersionBumperTest.php b/tests/Composer/Test/Package/Version/VersionBumperTest.php index b8f07844f..c5cd86b15 100644 --- a/tests/Composer/Test/Package/Version/VersionBumperTest.php +++ b/tests/Composer/Test/Package/Version/VersionBumperTest.php @@ -44,6 +44,7 @@ class VersionBumperTest extends TestCase { // constraint, version, expected recommendation, [branch-alias] yield 'upgrade caret' => ['^1.0', '1.2.1', '^1.2.1']; + yield 'upgrade caret with v' => ['^v1.0', '1.2.1', '^1.2.1']; yield 'skip trailing .0s' => ['^1.0', '1.0.0', '^1.0']; yield 'skip trailing .0s/2' => ['^1.2', '1.2.0', '^1.2']; yield 'preserve major.minor.patch format when installed minor is 0' => ['^1.0.0', '1.2.0', '^1.2.0']; @@ -58,6 +59,7 @@ class VersionBumperTest extends TestCase yield 'dev version does not upgrade' => ['^3.2', 'dev-main', '^3.2']; yield 'upgrade dev version if aliased' => ['^3.2', 'dev-main', '^3.3', '3.3.x-dev']; yield 'upgrade major wildcard to caret' => ['2.*', '2.4.0', '^2.4']; + yield 'upgrade major wildcard to caret with v' => ['v2.*', '2.4.0', '^2.4']; yield 'upgrade major wildcard as x to caret' => ['2.x', '2.4.0', '^2.4']; yield 'upgrade major wildcard as x to caret/2' => ['2.x.x', '2.4.0', '^2.4.0']; yield 'leave minor wildcard alone' => ['2.4.*', '2.4.3', '2.4.*']; @@ -66,6 +68,7 @@ class VersionBumperTest extends TestCase yield 'update patch-only-tilde alone' => ['~2.2.3', '2.2.6', '~2.2.6']; 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 'upgrade bigger-or-eq to latest with v' => ['>=v3.0', '3.4.5', '>=3.4.5']; yield 'leave bigger-than untouched' => ['>2.2.3', '2.2.6', '>2.2.3']; } }