diff --git a/Sparkle/SUAppcastDriver.m b/Sparkle/SUAppcastDriver.m index 64366002e4..d21fc6be4d 100644 --- a/Sparkle/SUAppcastDriver.m +++ b/Sparkle/SUAppcastDriver.m @@ -153,6 +153,7 @@ + (SUAppcastItem * _Nullable)bestItemFromAppcastItems:(NSArray *)appcastItems co { SUAppcastItem *item = nil; for(SUAppcastItem *candidate in appcastItems) { + // Note if two items are equal, we must select the first matching one if (!item || [comparator compareVersion:item.versionString toVersion:candidate.versionString] == NSOrderedAscending) { item = candidate; } diff --git a/Sparkle/SUStandardVersionComparator.m b/Sparkle/SUStandardVersionComparator.m index a2958e82b8..77491e9a18 100644 --- a/Sparkle/SUStandardVersionComparator.m +++ b/Sparkle/SUStandardVersionComparator.m @@ -33,12 +33,15 @@ typedef NS_ENUM(NSInteger, SUCharacterType) { kNumberType, kStringType, kSeparatorType, + kDashType, }; - (SUCharacterType)typeOfCharacter:(NSString *)character { if ([character isEqualToString:@"."]) { return kSeparatorType; + } else if ([character isEqualToString:@"-"]) { + return kDashType; } else if ([[NSCharacterSet decimalDigitCharacterSet] characterIsMember:[character characterAtIndex:0]]) { return kNumberType; } else if ([[NSCharacterSet whitespaceAndNewlineCharacterSet] characterIsMember:[character characterAtIndex:0]]) { @@ -67,6 +70,9 @@ - (NSArray *)splitVersionString:(NSString *)version for (i = 1; i <= n; ++i) { character = [version substringWithRange:NSMakeRange(i, 1)]; newType = [self typeOfCharacter:character]; + if (newType == kDashType) { + break; + } if (oldType != newType || oldType == kSeparatorType) { // We've reached a new segment NSString *aPart = [[NSString alloc] initWithString:s]; diff --git a/Tests/SUVersionComparisonTest.m b/Tests/SUVersionComparisonTest.m index 6db0374650..b53b8c64df 100644 --- a/Tests/SUVersionComparisonTest.m +++ b/Tests/SUVersionComparisonTest.m @@ -33,6 +33,15 @@ - (void)testNumbers SUAssertAscending(comparator, @"0.1", @"0.1.2"); } +- (void)testCommitSHAs +{ + SUStandardVersionComparator *comparator = [[SUStandardVersionComparator alloc] init]; + + SUAssertAscending(comparator, @"1.5.5-335d3e2", @"1.5.6-b252311"); + SUAssertEqual(comparator, @"1.5.5-335d3e2", @"1.5.5-a655360"); + SUAssertDescending(comparator, @"1.5.6-b252311", @"1.5.5-335d3e2"); +} + - (void)testPrereleases { SUStandardVersionComparator *comparator = [[SUStandardVersionComparator alloc] init];