Skip to content

Commit

Permalink
Support larger MAJOR version numbers (#149)
Browse files Browse the repository at this point in the history
* 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"

* Reduce repetition count to a saner level to retry CI

* Add new formats without breaking any existing ones

---------

Co-authored-by: Jordi Boggiano <j.boggiano@seld.be>
  • Loading branch information
onethumb and Seldaek committed Aug 30, 2023
1 parent fa1ec24 commit ce46554
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/VersionParser.php
Expand Up @@ -134,14 +134,14 @@ 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,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;
}
Expand Down
9 changes: 9 additions & 0 deletions tests/VersionParserTest.php
Expand Up @@ -86,7 +86,15 @@ 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'),
'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'),
Expand Down Expand Up @@ -170,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'),
);
}

Expand Down

0 comments on commit ce46554

Please sign in to comment.