From 2e6e152b8009533893ee59be28f2f474e74ce118 Mon Sep 17 00:00:00 2001 From: Don MacAskill Date: Tue, 31 Jan 2023 17:04:45 -0800 Subject: [PATCH 1/3] Support larger MAJOR version numbers - We prefer to use CalVer + SemVer (YYYYMMDD as MAJOR) for versioning. - Other software, like `npm`, supports this: https://github.com/npm/node-semver/blob/bdda212f4f6126a1b8821dc0731a17fdc2fc533f/classes/semver.js#L48 - Composer breaks with an invalid version string: root@0c6964ad69d6:/var/project# COMPOSER_ROOT_VERSION=20230131.0.0 composer install [UnexpectedValueException] Invalid version string "20230131.0.0" --- src/VersionParser.php | 2 +- tests/VersionParserTest.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/VersionParser.php b/src/VersionParser.php index 0b0bc506..fb1d0f23 100644 --- a/src/VersionParser.php +++ b/src/VersionParser.php @@ -134,7 +134,7 @@ public function normalize($version, $fullVersion = null) } // match classical versioning - if (preg_match('{^v?(\d{1,5})(\.\d++)?(\.\d++)?(\.\d++)?' . self::$modifierRegex . '$}i', $version, $matches)) { + if (preg_match('{^v?(\d{1,' . PHP_INT_MAX . '})(\.\d++)?(\.\d++)?(\.\d++)?' . self::$modifierRegex . '$}i', $version, $matches)) { $version = $matches[1] . (!empty($matches[2]) ? $matches[2] : '.0') . (!empty($matches[3]) ? $matches[3] : '.0') diff --git a/tests/VersionParserTest.php b/tests/VersionParserTest.php index e981e87b..55858b53 100644 --- a/tests/VersionParserTest.php +++ b/tests/VersionParserTest.php @@ -86,6 +86,9 @@ public function successfulNormalizedVersions() 'parses dates w/ . as classical' => array('2010.01.02', '2010.01.02.0'), 'parses dates y.m.Y as classical' => array('2010.1.555', '2010.1.555.0'), 'parses dates y.m.Y/2 as classical' => array('2010.10.200', '2010.10.200.0'), + 'parses CalVer YYYYMMDD (as MAJOR) versions' => array('20230131.0.0', '20230131.0.0'), + 'parses CalVer YYYYMMDDhhmm (as MAJOR) versions' => array('202301310000.0.0', '202301310000.0.0'), + 'parses PHP_INT_MAX MAJOR version' => array(PHP_INT_MAX . '.0.0', PHP_INT_MAX . '.0.0'), 'strips v/datetime' => array('v20100102', '20100102'), 'parses dates w/ -' => array('2010-01-02', '2010.01.02'), 'parses dates w/ .' => array('2012.06.07', '2012.06.07.0'), From 249b023d3980d8001d9e3ab0d821cf1493d73221 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 1 Feb 2023 08:33:22 +0100 Subject: [PATCH 2/3] Reduce repetition count to a saner level to retry CI --- src/VersionParser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VersionParser.php b/src/VersionParser.php index fb1d0f23..714ca20e 100644 --- a/src/VersionParser.php +++ b/src/VersionParser.php @@ -134,7 +134,7 @@ public function normalize($version, $fullVersion = null) } // match classical versioning - if (preg_match('{^v?(\d{1,' . PHP_INT_MAX . '})(\.\d++)?(\.\d++)?(\.\d++)?' . self::$modifierRegex . '$}i', $version, $matches)) { + if (preg_match('{^v?(\d{1,20})(\.\d++)?(\.\d++)?(\.\d++)?' . self::$modifierRegex . '$}i', $version, $matches)) { $version = $matches[1] . (!empty($matches[2]) ? $matches[2] : '.0') . (!empty($matches[3]) ? $matches[3] : '.0') From c42e6c281c815e2277806f21ee40c6a5d4f679fa Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 20 Jul 2023 13:30:54 +0200 Subject: [PATCH 3/3] Add new formats without breaking any existing ones --- src/VersionParser.php | 4 ++-- tests/VersionParserTest.php | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/VersionParser.php b/src/VersionParser.php index 714ca20e..9318629a 100644 --- a/src/VersionParser.php +++ b/src/VersionParser.php @@ -134,14 +134,14 @@ public function normalize($version, $fullVersion = null) } // match classical versioning - if (preg_match('{^v?(\d{1,20})(\.\d++)?(\.\d++)?(\.\d++)?' . self::$modifierRegex . '$}i', $version, $matches)) { + if (preg_match('{^v?(\d{1,5}+)(\.\d++)?(\.\d++)?(\.\d++)?' . self::$modifierRegex . '$}i', $version, $matches)) { $version = $matches[1] . (!empty($matches[2]) ? $matches[2] : '.0') . (!empty($matches[3]) ? $matches[3] : '.0') . (!empty($matches[4]) ? $matches[4] : '.0'); $index = 5; // match date(time) based versioning - } elseif (preg_match('{^v?(\d{4}(?:[.:-]?\d{2}){1,6}(?:[.:-]?\d{1,3})?)' . self::$modifierRegex . '$}i', $version, $matches)) { + } elseif (preg_match('{^v?(\d{4}(?:[.:-]?\d{2}){1,6}(?:[.:-]?\d{1,3}){0,2})' . self::$modifierRegex . '$}i', $version, $matches)) { $version = (string) preg_replace('{\D}', '.', $matches[1]); $index = 2; } diff --git a/tests/VersionParserTest.php b/tests/VersionParserTest.php index 55858b53..64988369 100644 --- a/tests/VersionParserTest.php +++ b/tests/VersionParserTest.php @@ -88,8 +88,13 @@ public function successfulNormalizedVersions() 'parses dates y.m.Y/2 as classical' => array('2010.10.200', '2010.10.200.0'), 'parses CalVer YYYYMMDD (as MAJOR) versions' => array('20230131.0.0', '20230131.0.0'), 'parses CalVer YYYYMMDDhhmm (as MAJOR) versions' => array('202301310000.0.0', '202301310000.0.0'), - 'parses PHP_INT_MAX MAJOR version' => array(PHP_INT_MAX . '.0.0', PHP_INT_MAX . '.0.0'), 'strips v/datetime' => array('v20100102', '20100102'), + 'parses dates no delimiter' => array('20100102', '20100102'), + 'parses dates no delimiter/2' => array('20100102.0', '20100102.0'), + 'parses dates no delimiter/3' => array('20100102.1.0', '20100102.1.0'), + 'parses dates no delimiter/4' => array('20100102.0.3', '20100102.0.3'), + 'parses dates w/ - and .' => array('2010-01-02-10-20-30.0.3', '2010.01.02.10.20.30.0.3'), + 'parses dates w/ - and ./2' => array('2010-01-02-10-20-30.5', '2010.01.02.10.20.30.5'), 'parses dates w/ -' => array('2010-01-02', '2010.01.02'), 'parses dates w/ .' => array('2012.06.07', '2012.06.07.0'), 'parses numbers' => array('2010-01-02.5', '2010.01.02.5'), @@ -173,6 +178,7 @@ public function failingNormalizedVersions() 'constraint' => array('~1'), 'constraint/2' => array('^1'), 'constraint/3' => array('1.*'), + 'date versions with 4 bits' => array('20100102.0.3.4', '20100102.0.3.4'), ); }