From 974fafa0170cddf307d07f9bdbfe86c8c03b63b0 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Wed, 21 Mar 2018 00:40:05 +0300 Subject: [PATCH] Treat any unknown version as 0.0.1, mark version field as required in InfoChecker --- lib/private/App/CodeChecker/InfoChecker.php | 2 +- lib/private/AppConfig.php | 7 +++++++ tests/lib/App/CodeChecker/InfoCheckerTest.php | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/private/App/CodeChecker/InfoChecker.php b/lib/private/App/CodeChecker/InfoChecker.php index 7b49ebaf49cf..a16d8bbc2441 100644 --- a/lib/private/App/CodeChecker/InfoChecker.php +++ b/lib/private/App/CodeChecker/InfoChecker.php @@ -36,6 +36,7 @@ class InfoChecker extends BasicEmitter { 'id', 'licence', 'name', + 'version', ]; private $optionalFields = [ 'bugs', @@ -49,7 +50,6 @@ class InfoChecker extends BasicEmitter { 'remote', 'repository', 'types', - 'version', 'website', ]; private $deprecatedFields = [ diff --git a/lib/private/AppConfig.php b/lib/private/AppConfig.php index e249e9258a5d..f35215d03cd7 100644 --- a/lib/private/AppConfig.php +++ b/lib/private/AppConfig.php @@ -302,6 +302,13 @@ protected function loadConfigValues() { $this->cache[$row['appid']] = []; } + // check if installed_version matches the pattern + // one_or_more_digits-dot-one_or_more_digits-any-other-characters + if ($row['configkey'] === 'installed_version' + && preg_match('/\d+\.\d+.*$/', $row['configvalue']) !== 1 + ) { + $row['configvalue'] = '0.0.1'; + } $this->cache[$row['appid']][$row['configkey']] = $row['configvalue']; } $result->closeCursor(); diff --git a/tests/lib/App/CodeChecker/InfoCheckerTest.php b/tests/lib/App/CodeChecker/InfoCheckerTest.php index 94de6bced0c5..3db71ee1ea41 100644 --- a/tests/lib/App/CodeChecker/InfoCheckerTest.php +++ b/tests/lib/App/CodeChecker/InfoCheckerTest.php @@ -50,10 +50,10 @@ protected function setUp() { public function appInfoData() { return [ ['testapp-infoxml', []], - ['testapp-version', []], + ['testapp-version', [['type' => 'mandatoryFieldMissing', 'field' => 'version']]], ['testapp-infoxml-version', []], ['testapp-infoxml-version-different', [['type' => 'differentVersions', 'message' => 'appinfo/version: 1.2.4 - appinfo/info.xml: 1.2.3']]], - ['testapp-version-missing', []], + ['testapp-version-missing', [['type' => 'mandatoryFieldMissing', 'field' => 'version']]], ['testapp-name-missing', [['type' => 'mandatoryFieldMissing', 'field' => 'name']]], ]; }