From 42e0d40e626030fe16a491c45cd5d621222daac7 Mon Sep 17 00:00:00 2001 From: Lucas Bickel Date: Thu, 23 Mar 2017 13:48:49 +0100 Subject: [PATCH] Make version comparision robust This needed to take various git version into account as per https://github.com/LibreTime/libretime/pull/102#issuecomment-288707322. It also had a bug where it would do the completely wrong thing with the currentParts array if a git commit-ish was treated as a version by mistake. --- airtime_mvc/application/views/helpers/VersionNotify.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/airtime_mvc/application/views/helpers/VersionNotify.php b/airtime_mvc/application/views/helpers/VersionNotify.php index 7e6c873c2..ca9aaf419 100644 --- a/airtime_mvc/application/views/helpers/VersionNotify.php +++ b/airtime_mvc/application/views/helpers/VersionNotify.php @@ -23,11 +23,14 @@ class Airtime_View_Helper_VersionNotify extends Zend_View_Helper_Abstract { $latest = Application_Model_Preference::GetLatestVersion(); $link = Application_Model_Preference::GetLatestLink(); - $isGitRelease = preg_match('/^[[:alnum:]]{7}$/i', $current) === 1; - $currentParts = array(0, 0, 0, 0); + $isGitRelease = preg_match('/^[[:alnum:]]{7,}$/i', $current) === 1; + $currentParts = array(); if (!$isGitRelease) { $currentParts = preg_split("/(\.|-)/", $current); } + if (count($currentParts) < 3) { + $currentParts = array(0, 0, 0, 0); + } $majorCandidates = SemVer::satisfiedBy($latest, sprintf('>=%1$s', $currentParts[0] + 1)); $minorCandidates = SemVer::satisfiedBy($latest, sprintf('~%1$s.%2$s', $currentParts[0], $currentParts[1] + 1));