From 4a3397766f32ef7e0335b3667b43db7e6e15e8f3 Mon Sep 17 00:00:00 2001 From: Fettlaus Date: Thu, 28 Jul 2022 16:23:33 +0200 Subject: [PATCH] Add fallback for missing version information in database (#1175) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Describe what your pull request does and which issue you’re targeting As described in #1174 the app crashes if a bogus version (empty string) is stored in the database. In case of an empty version information in the database, the fallback should be to gracefully treat this as a version 0. This way every check for a "version greater than" fails. After all the version information will be updated from the server anyways.
fixes #1174
- [X] I carefully read the [contribution guidelines](https://codeberg.org/GitNex/GitNex/src/branch/main/CONTRIBUTING.md). - [X] I'm following the code standards as defined [here](https://codeberg.org/gitnex/GitNex/wiki/Code-Standards). - [X] By submitting this pull request, I permit GitNex to license my work under the [GNU General Public License v3](https://codeberg.org/GitNex/GitNex/src/branch/main/LICENSE). Co-authored-by: Fettlaus Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1175 Reviewed-by: qwerty287 Co-authored-by: Fettlaus Co-committed-by: Fettlaus --- app/src/main/java/org/mian/gitnex/helpers/Version.java | 4 ++++ app/src/test/java/org/mian/gitnex/helpers/VersionTest.java | 2 ++ 2 files changed, 6 insertions(+) diff --git a/app/src/main/java/org/mian/gitnex/helpers/Version.java b/app/src/main/java/org/mian/gitnex/helpers/Version.java index 08312729..908d0457 100644 --- a/app/src/main/java/org/mian/gitnex/helpers/Version.java +++ b/app/src/main/java/org/mian/gitnex/helpers/Version.java @@ -51,6 +51,10 @@ public class Version { final Pattern patternNumberDotNumber = Pattern.compile("^\\d+(\\.(\\d)+)*"); + if(raw.isEmpty()) { + raw = "0"; + } + if(!valid(raw)) { throw new IllegalArgumentException("Invalid version format: " + raw); } diff --git a/app/src/test/java/org/mian/gitnex/helpers/VersionTest.java b/app/src/test/java/org/mian/gitnex/helpers/VersionTest.java index 34bada6b..ccce0fbc 100644 --- a/app/src/test/java/org/mian/gitnex/helpers/VersionTest.java +++ b/app/src/test/java/org/mian/gitnex/helpers/VersionTest.java @@ -20,6 +20,7 @@ public class VersionTest { assertTrue(new Version("1.12.0").equal("v1.12")); assertTrue(new Version("v1.12.0").equal("1.12.0")); assertTrue(new Version("0").equal("0")); + assertTrue(new Version("").equal("0")); assertFalse(new Version("1.12.1").equal("1.12.0+dev-211-g316db0fe7")); assertFalse(new Version("v1.12.0").equal("1.10.0")); @@ -35,6 +36,7 @@ public class VersionTest { @Test public void less() { + assertTrue(new Version("").less("1.11.0")); assertTrue(new Version("1.11.0").less("1.12")); assertTrue(new Version("v1.11").less("1.12.0+dev-211-g316db0fe7")); assertTrue(new Version("1.12.0").less("v2"));