Skip to content

Commit

Permalink
Merge pull request #1845 from sparkle-project/version-dash-separator
Browse files Browse the repository at this point in the history
Port #1504 (dash separators in version strings) to 2.x
  • Loading branch information
zorgiepoo authored May 2, 2021
2 parents 5da8199 + 9a12dbf commit c79785a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions Sparkle/SUAppcastDriver.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
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
9 changes: 9 additions & 0 deletions Tests/SUVersionComparisonTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit c79785a

Please sign in to comment.