diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2021-01-27 15:14:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-27 15:14:52 +0100 |
commit | 3a9c7f99f632f973caaf6a7aca5ca9294bb11db3 (patch) | |
tree | e909e1964868f5985c539cf5e53e3ad70a39d20d /lib | |
parent | e0f0e6e41a47dbdb5fbe3527dc923dfbc1ea37e1 (diff) | |
parent | b4f71ccf4dd43332ab92eb860604c2308cb36a9d (diff) | |
download | nextcloud-server-3a9c7f99f632f973caaf6a7aca5ca9294bb11db3.tar.gz nextcloud-server-3a9c7f99f632f973caaf6a7aca5ca9294bb11db3.zip |
Merge pull request #25335 from nextcloud/fix/app-fetcher-php-compat-comparison
Fix/app fetcher php compat comparison
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/App/AppStore/Fetcher/AppFetcher.php | 4 | ||||
-rw-r--r-- | lib/private/App/CompareVersion.php | 25 |
2 files changed, 17 insertions, 12 deletions
diff --git a/lib/private/App/AppStore/Fetcher/AppFetcher.php b/lib/private/App/AppStore/Fetcher/AppFetcher.php index 70bf2a37d9d..4dc517879e8 100644 --- a/lib/private/App/AppStore/Fetcher/AppFetcher.php +++ b/lib/private/App/AppStore/Fetcher/AppFetcher.php @@ -113,12 +113,12 @@ class AppFetcher extends Fetcher { $phpVersion = $versionParser->getVersion($release['rawPhpVersionSpec']); $minPhpVersion = $phpVersion->getMinimumVersion(); $maxPhpVersion = $phpVersion->getMaximumVersion(); - $minPhpFulfilled = $minPhpVersion === '' || version_compare( + $minPhpFulfilled = $minPhpVersion === '' || $this->compareVersion->isCompatible( PHP_VERSION, $minPhpVersion, '>=' ); - $maxPhpFulfilled = $maxPhpVersion === '' || version_compare( + $maxPhpFulfilled = $maxPhpVersion === '' || $this->compareVersion->isCompatible( PHP_VERSION, $maxPhpVersion, '<=' diff --git a/lib/private/App/CompareVersion.php b/lib/private/App/CompareVersion.php index 5d38d4c358e..9df28a457ff 100644 --- a/lib/private/App/CompareVersion.php +++ b/lib/private/App/CompareVersion.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @copyright 2018 Christoph Wurst <christoph@winzerhof-wurst.at> * @@ -24,12 +27,13 @@ namespace OC\App; use InvalidArgumentException; +use function explode; class CompareVersion { - public const REGEX_MAJOR = '/^\d+$/'; - public const REGEX_MAJOR_MINOR = '/^\d+.\d+$/'; - public const REGEX_MAJOR_MINOR_PATCH = '/^\d+.\d+.\d+$/'; - public const REGEX_SERVER = '/^\d+.\d+.\d+(.\d+)?$/'; + private const REGEX_MAJOR = '/^\d+$/'; + private const REGEX_MAJOR_MINOR = '/^\d+\.\d+$/'; + private const REGEX_MAJOR_MINOR_PATCH = '/^\d+\.\d+\.\d+(?!\.\d+)/'; + private const REGEX_ACTUAL = '/^\d+(\.\d+){1,2}/'; /** * Checks if the given server version fulfills the given (app) version requirements. @@ -45,18 +49,19 @@ class CompareVersion { */ public function isCompatible(string $actual, string $required, string $comparator = '>='): bool { - if (!preg_match(self::REGEX_SERVER, $actual)) { - throw new InvalidArgumentException('server version is invalid'); + if (!preg_match(self::REGEX_ACTUAL, $actual, $matches)) { + throw new InvalidArgumentException("version specification $actual is invalid"); } + $cleanActual = $matches[0]; if (preg_match(self::REGEX_MAJOR, $required) === 1) { - return $this->compareMajor($actual, $required, $comparator); + return $this->compareMajor($cleanActual, $required, $comparator); } elseif (preg_match(self::REGEX_MAJOR_MINOR, $required) === 1) { - return $this->compareMajorMinor($actual, $required, $comparator); + return $this->compareMajorMinor($cleanActual, $required, $comparator); } elseif (preg_match(self::REGEX_MAJOR_MINOR_PATCH, $required) === 1) { - return $this->compareMajorMinorPatch($actual, $required, $comparator); + return $this->compareMajorMinorPatch($cleanActual, $required, $comparator); } else { - throw new InvalidArgumentException('required version is invalid'); + throw new InvalidArgumentException("required version $required is invalid"); } } |