semver icon indicating copy to clipboard operation
semver copied to clipboard

[Sorting] Captial Release Candidate is sorted before alpha releases

Open Sijoma opened this issue 10 months ago • 1 comments

I'm not sure if its intended or not. Versions with a capital release candidate [-RC] are sorted before the -alpha.. releases. Lower case [-rc] then comes at the end.

A quick example when having the following versions:

Versions: 1.2.3, 8.5.0-rc2, 1.0, 8.5.0-alpha2, 8.5.0-RC2, 1.3, 2, 0.4.2 Sorted Output: 0.4.2, 1.0.0, 1.2.3, 1.3.0, 2.0.0, 8.5.0-RC2, 8.5.0-alpha2, 8.5.0-rc2

Expected Output: 0.4.2, 1.0.0, 1.2.3, 1.3.0, 2.0.0, 8.5.0-alpha2, 8.5.0-rc2, 8.5.0-RC2

Go Playground: https://go.dev/play/p/-X6MZ0OFYJT

Sijoma avatar Apr 02 '24 14:04 Sijoma

I can explain a little about what's going on. For SemVer there is a spec at https://semver.org. In the spec it specifically states:

Identifiers with letters or hyphens are compared lexically in ASCII sort order.

So, what is ASCII sort order? You can visualize it at sites like https://www.ascii-code.com. Ordering has all uppercase letters coming before lowercase letters. This is why you get the output you see. It's following the spec.

mattfarina avatar Apr 30 '24 15:04 mattfarina