diff --git a/lib/versions.ps1 b/lib/versions.ps1 index a3a1309ca1..5b2583d87e 100644 --- a/lib/versions.ps1 +++ b/lib/versions.ps1 @@ -181,6 +181,17 @@ function Compare-Version { } } + # If some parts of versions have '_', compare them with delimiter '_' + if (($splitReferenceVersion[$i] -match '_') -or ($splitDifferenceVersion[$i] -match '_')) { + $Result = Compare-Version -ReferenceVersion $splitReferenceVersion[$i] -DifferenceVersion $splitDifferenceVersion[$i] -Delimiter '_' + # If the parts are equal, continue to next part, otherwise return + if ($Result -ne 0) { + return $Result + } else { + continue + } + } + # Don't try to compare [Long] to [String] if ($null -ne $splitReferenceVersion[$i] -and $null -ne $splitDifferenceVersion[$i]) { if ($splitReferenceVersion[$i] -is [String] -and $splitDifferenceVersion[$i] -isnot [String]) { diff --git a/test/Scoop-Versions.Tests.ps1 b/test/Scoop-Versions.Tests.ps1 index 8fee628604..d039a7e719 100644 --- a/test/Scoop-Versions.Tests.ps1 +++ b/test/Scoop-Versions.Tests.ps1 @@ -51,6 +51,7 @@ Describe 'versions comparison' -Tag 'Scoop' { Compare-Version '1.4' '1.3.255.255' | Should -Be -1 Compare-Version '1.4' '1.4.4' | Should -Be 1 Compare-Version '1.1.1_8' '1.1.1' | Should -Be -1 + Compare-Version '1.1.1_8' '1.1.1_9' | Should -Be 1 Compare-Version '1.1.1b' '1.1.1a' | Should -Be -1 Compare-Version '1.1.1a' '1.1.1b' | Should -Be 1 Compare-Version '1.1a2' '1.1a3' | Should -Be 1