Skip to content

Commit

Permalink
Merge pull request #20 from dontub/fix-pre-release-comparison
Browse files Browse the repository at this point in the history
Fix comparison when identifier of pre release contains both letters and numbers
  • Loading branch information
nikolaposa authored Aug 18, 2018
2 parents a29a374 + b42cf60 commit 251205f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Extension/PreRelease.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ public function compareTo(PreRelease $preRelease) : int

private function compareIdentifiers($identifier1, $identifier2) : int
{
$pr1IsAlpha = ctype_alpha($identifier1);
$pr2IsAlpha = ctype_alpha($identifier2);
$identifier1IsNumber = ctype_digit($identifier1);
$identifier2IsNumber = ctype_digit($identifier2);

if ($pr1IsAlpha xor $pr2IsAlpha) {
return $pr1IsAlpha ? 1 : -1;
if ($identifier1IsNumber xor $identifier2IsNumber) {
return $identifier1IsNumber ? -1 : 1;
}

if (ctype_digit($identifier1) && ctype_digit($identifier2)) {
if ($identifier1IsNumber && $identifier2IsNumber) {
return (int) $identifier1 - (int) $identifier2;
}

Expand Down
1 change: 1 addition & 0 deletions tests/Comparator/SemverComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public static function getExpectedResultsOfComparisonVersions() : array
['1.0.0-rc.1.1', '1.0.0-rc.1', 1],
['1.0.0', '1.0.0-rc.1', 1],
['1.0.0-alpha+20150919', '1.0.0-alpha+exp.sha.5114f85', 0],
['1.0.0-b1', '1.0.0-a', 1],
];
}
}

0 comments on commit 251205f

Please sign in to comment.