Skip to content

Commit

Permalink
fix(versions): Fix situation that contains '_'
Browse files Browse the repository at this point in the history
  • Loading branch information
niheaven committed Nov 15, 2021
1 parent 6c2b34d commit ae89213
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/versions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
1 change: 1 addition & 0 deletions test/Scoop-Versions.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ae89213

Please sign in to comment.