Skip to content

Commit 241ec65

Browse files
committed
Fix version sorting
This whole time it was just coincidentally passing the tests.
1 parent d95bd20 commit 241ec65

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

storage/storage.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ type ByVersion []Version
182182
func (vs ByVersion) Len() int { return len(vs) }
183183
func (vs ByVersion) Swap(i, j int) { vs[i], vs[j] = vs[j], vs[i] }
184184
func (vs ByVersion) Less(i, j int) bool {
185-
cmp := semver.Compare(vs[i].Version, vs[j].Version)
185+
// Go's semver library requires a v prefix.
186+
cmp := semver.Compare("v"+vs[i].Version, "v"+vs[j].Version)
186187
if cmp != 0 {
187188
return cmp >= 0
188189
}

storage/storage_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,17 @@ func TestSortByVersion(t *testing.T) {
11591159
{Version: "1.0.0", TargetPlatform: storage.PlatformWin32X64},
11601160
},
11611161
},
1162+
{
1163+
name: "CompareMSPythonStyle",
1164+
versions: []storage.Version{
1165+
{Version: "2023.9.1102792234"},
1166+
{Version: "2023.10.1002811100"},
1167+
},
1168+
expected: []storage.Version{
1169+
{Version: "2023.10.1002811100"},
1170+
{Version: "2023.9.1102792234"},
1171+
},
1172+
},
11621173
}
11631174

11641175
for _, test := range tests {

0 commit comments

Comments
 (0)