Skip to content

Commit acb116b

Browse files
authored
Fixed issue related to compare unnormalized versions (#31)
1 parent e9a161a commit acb116b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/Diff.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
namespace JBZoo\ComposerDiff;
1818

1919
use Composer\Semver\Comparator;
20+
use Composer\Semver\VersionParser;
2021

2122
final class Diff
2223
{
@@ -103,11 +104,16 @@ public function compareWithPackage(Package $targetPackage): self
103104
return $this->setMode(self::MODE_CHANGED);
104105
}
105106

106-
if (Comparator::greaterThan($sourceVersion, $targetVersion)) {
107+
$parser = new VersionParser();
108+
109+
$normalizedSource = $parser->normalize($sourceVersion);
110+
$normalizedTarget = $parser->normalize($targetVersion);
111+
112+
if (Comparator::greaterThan($normalizedSource, $normalizedTarget)) {
107113
return $this->setMode(self::MODE_DOWNGRADED);
108114
}
109115

110-
if (Comparator::lessThan($sourceVersion, $targetVersion)) {
116+
if (Comparator::lessThan($normalizedSource, $normalizedTarget)) {
111117
return $this->setMode(self::MODE_UPGRADED);
112118
}
113119

0 commit comments

Comments
 (0)