From be6514208ef29e9ed6f8d951353f955ebd93049c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Fri, 14 Sep 2018 17:15:20 +0200 Subject: [PATCH] Fix argumenterror for invalid semver database versions [ci skip] --- lib/open_project/database.rb | 3 +++ spec/lib/database_spec.rb | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/lib/open_project/database.rb b/lib/open_project/database.rb index bff2b6e3e8..5d68180f7d 100644 --- a/lib/open_project/database.rb +++ b/lib/open_project/database.rb @@ -139,6 +139,9 @@ module OpenProject def self.semantic_version(version_string = self.version) Semantic::Version.new version_string + rescue ArgumentError + # Cut anything behind the - + Semantic::Version.new version_string.gsub(/\-.+$/, '') end def self.numeric_version diff --git a/spec/lib/database_spec.rb b/spec/lib/database_spec.rb index 78c173974e..272fc50c4a 100644 --- a/spec/lib/database_spec.rb +++ b/spec/lib/database_spec.rb @@ -44,6 +44,11 @@ describe OpenProject::Database do version3 = OpenProject::Database.semantic_version '10.1.26-MariaDB-0+deb9u1' expect(version3.major).to eq 10 + + version4 = OpenProject::Database.semantic_version '5.7.23-0ubuntu0.16.04.1' + expect(version4.major).to eq 5 + # Cuts the build if its invalid semver + expect(version4.build).to be_nil end it 'should be able to use the helper methods' do