[BUGFIX] improve handling of TYPO3 version 09/27509/5
authorJigal van Hemert <jigal.van.hemert@typo3.org>
Sun, 9 Feb 2014 12:01:45 +0000 (13:01 +0100)
committerMarkus Klein <klein.t3@mfc-linz.at>
Sun, 9 Feb 2014 18:17:09 +0000 (19:17 +0100)
getNumericTypo3Version() needs to be more flexible when converting
the defined version number into one that can be used by the EM.

Resolves: #23902
Releases: 6.2
Change-Id: Ie2ed54c1383e3c6ff9631608e2e9e471ef109952
Reviewed-on: https://review.typo3.org/27509
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/core/Classes/Utility/VersionNumberUtility.php
typo3/sysext/core/Tests/Unit/Utility/VersionNumberUtilityTest.php

index 344e2c1..070a3cf 100644 (file)
@@ -92,17 +92,18 @@ class VersionNumberUtility {
        }
 
        /**
-        * Removes -dev -alpha -beta -RC states from a version number
-        * and replaces them by .0
+        * Removes -dev -alpha -beta -RC states (also without '-' prefix) from a version number
+        * and replaces them by .0 and normalizes to a three part version number
         *
         * @return string
         */
        static public function getNumericTypo3Version() {
                $t3version = static::getCurrentTypo3Version();
-               if (stripos($t3version, '-dev') || stripos($t3version, '-alpha') || stripos($t3version, '-beta') || stripos($t3version, '-RC')) {
-                       // find the last occurence of "-" and replace that part with a ".0"
-                       $t3version = substr($t3version, 0, strrpos($t3version, '-')) . '.0';
-               }
+               $t3version = preg_replace('/-?(dev|alpha|beta|RC).*$/', '', $t3version);
+               $parts = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode('.', $t3version . '..');
+               $t3version = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($parts[0], 0, 999) . '.' .
+                       \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($parts[1], 0, 999) . '.' .
+                       \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($parts[2], 0, 999);
                return $t3version;
        }
 
index 940607a..e4774b5 100644 (file)
@@ -119,7 +119,11 @@ class VersionNumberUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        array(
                                '6.0.1',
                                '6.0.1'
-                       )
+                       ),
+                       array(
+                               '6.2.0beta5',
+                               '6.2.0'
+                       ),
                );
        }