Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: properly compare versions with commit SHA #1504

Merged
merged 1 commit into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Sparkle/SUBasicUpdateDriver.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@ - (SUAppcastItem *)bestItemFromAppcastItems:(NSArray *)appcastItems getDeltaItem
SUAppcastItem *item = nil;
for(SUAppcastItem *candidate in appcastItems) {
if ([self hostSupportsItem:candidate]) {
if (!item || [comparator compareVersion:item.versionString toVersion:candidate.versionString] == NSOrderedAscending) {
if (
!item || (
[item.date compare:candidate.date] == NSOrderedAscending &&
[comparator compareVersion:item.versionString toVersion:candidate.versionString] != NSOrderedDescending
)
) {
item = candidate;
}
}
Expand Down
6 changes: 6 additions & 0 deletions Sparkle/SUStandardVersionComparator.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]]) {
Expand Down Expand Up @@ -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];
Expand Down
10 changes: 9 additions & 1 deletion Tests/SUVersionComparisonTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,18 @@ - (void)testNumbers
SUAssertAscending(comparator, @"0.1", @"0.1.2");
}

- (void)testPrereleases
- (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");
}

- (void)testPrereleases
{
SUStandardVersionComparator *comparator = [[SUStandardVersionComparator alloc] init];

SUAssertAscending(comparator, @"1.5.5", @"1.5.6a1");
SUAssertAscending(comparator, @"1.1.0b1", @"1.1.0b2");
SUAssertAscending(comparator, @"1.1.1b2", @"1.1.2b1");
Expand Down