diff --git a/core/src/net/sf/openrocket/communication/UpdateInfoRetriever.java b/core/src/net/sf/openrocket/communication/UpdateInfoRetriever.java index 4437340f0..96ede4c05 100644 --- a/core/src/net/sf/openrocket/communication/UpdateInfoRetriever.java +++ b/core/src/net/sf/openrocket/communication/UpdateInfoRetriever.java @@ -358,7 +358,14 @@ public class UpdateInfoRetriever { // If the loop is still going until this condition, you have the situation where tag1 is e.g. // '15.03' and tag2 '15.03.01', so tag is in that case the more recent version. if (i >= tag1Split.length) { - return ReleaseStatus.OLDER; + // Tag 1 is e.g. '15.03' and tag2 '15.03.01', so tag2 is the more recent version + if (tag2Split[i].matches("\\d+")) { + return ReleaseStatus.OLDER; + } + // Tag 1 is e.g. '15.03' and tag2 '15.03.beta.01', so tag1 is the more recent version (it's an official release) + else { + return ReleaseStatus.NEWER; + } } try { @@ -389,6 +396,8 @@ public class UpdateInfoRetriever { // a text, e.g. '20.01' if (tag2Split[i].matches("\\d+")) { return ReleaseStatus.OLDER; + } else if (tag1Split[i].matches("\\d+")) { + return ReleaseStatus.NEWER; } String message = String.format("Unrecognized release tag format, tag 1: %s, tag 2: %s", tag1, tag2); @@ -410,6 +419,12 @@ public class UpdateInfoRetriever { return ReleaseStatus.LATEST; } + /** + * Checks whether the release tag is malformed (e.g. empty, or containing invalid entries, such as negative numbers + * or unknown tags) + * @param tagSplit the tag split by '.' or '-' + * @throws UpdateCheckerException if the tag is malformed + */ private static void checkMalformedReleaseTag(String[] tagSplit) throws UpdateCheckerException { if (tagSplit.length == 0) { String message = "Zero-length tag"; diff --git a/core/test/net/sf/openrocket/communication/UpdateInfoTest.java b/core/test/net/sf/openrocket/communication/UpdateInfoTest.java index 95bf1e5ba..e6b03316d 100644 --- a/core/test/net/sf/openrocket/communication/UpdateInfoTest.java +++ b/core/test/net/sf/openrocket/communication/UpdateInfoTest.java @@ -185,6 +185,21 @@ public class UpdateInfoTest extends BaseTestCase { assertEquals(UpdateInfoRetriever.ReleaseStatus.OLDER, UpdateInfoRetriever.UpdateInfoFetcher.compareLatest("22.02.beta.01", "22.02.02")); + assertEquals(UpdateInfoRetriever.ReleaseStatus.OLDER, + UpdateInfoRetriever.UpdateInfoFetcher.compareLatest("22", "22.02.beta.01")); + assertEquals(UpdateInfoRetriever.ReleaseStatus.NEWER, + UpdateInfoRetriever.UpdateInfoFetcher.compareLatest("22.02", "22.02.beta.01")); + assertEquals(UpdateInfoRetriever.ReleaseStatus.NEWER, + UpdateInfoRetriever.UpdateInfoFetcher.compareLatest("22.02.01", "22.02.beta.01")); + assertEquals(UpdateInfoRetriever.ReleaseStatus.OLDER, + UpdateInfoRetriever.UpdateInfoFetcher.compareLatest("22", "22.02.beta.01")); + assertEquals(UpdateInfoRetriever.ReleaseStatus.NEWER, + UpdateInfoRetriever.UpdateInfoFetcher.compareLatest("22.03", "22.02.beta.01")); + assertEquals(UpdateInfoRetriever.ReleaseStatus.OLDER, + UpdateInfoRetriever.UpdateInfoFetcher.compareLatest("22.01", "22.02.beta.01")); + assertEquals(UpdateInfoRetriever.ReleaseStatus.NEWER, + UpdateInfoRetriever.UpdateInfoFetcher.compareLatest("22.02.02", "22.02.beta.01")); + assertEquals(UpdateInfoRetriever.ReleaseStatus.NEWER, UpdateInfoRetriever.UpdateInfoFetcher.compareLatest("22.02.RC.01", "22")); assertEquals(UpdateInfoRetriever.ReleaseStatus.OLDER,