mirror of
https://github.com/semver/semver.git
synced 2026-03-22 22:20:28 -05:00
How do "-" (hyphens) in the middle of pre-release and build numbers get sorted? #58
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @jasongregori on GitHub (Mar 14, 2013).
According to items 9 and 10: pre-release and build numbers can have "-" in them.
According to item 11: "Pre-release and build version precedence MUST be determined by comparing each dot separated identifier as follows: identifiers consisting of only digits are compared numerically and identifiers with letters or hyphens are compared lexically in ASCII sort order". I take this to mean that you should separate everything at each "." and compare those pieces separately according to those rules.
My question: is "1.0.0-rc.2-beta < 1.0.0-rc.11-beta" correct?
I would think this would be true, but if I separated by dots I eventually get to "2-beta" vs "11-beta". Following the instructions of "identifiers with letters or hyphens are compared lexically in ASCII sort order", "2-beta" would be > "11-beta" so the above would be incorrect.
Personally, I don't like being able to have hyphens in pre-release and build numbers even makes much sense. But I want to sort these and I want to do it correctly.
Thanks!
@haacked commented on GitHub (Mar 15, 2013):
Hi @jasongregori.
-hyphen is ASCII 45 which means it does precede0-9A-Za-z. So it would seem that:1.0.0-rc.2-beta<1.0.0-rc.11-betais not correct. As you point out, ASCII sort order would place2-betaafter11-beta.Clearly that goes against what people might expect so I'd just recommend doing this:
1.0.0-rc.2.beta<1.0.0-rc.11.betawhich sorts in the way you expect.@EddieGarmon commented on GitHub (Mar 15, 2013):
Then doesn't it make more sense to remove it from the allowed characters, than to leave it and have confused consumers?
@haacked commented on GitHub (Mar 15, 2013):
Not necessarily. You may have good reasons to use it.
1.0.0-experimental-betaAlso, you have the same problem anyways without the dash:1.0.0-beta11<1.0.0-beta2.I think there will always be cases where it's possible to do something confusing and we can't prevent them all.
BTW, I'm closing this unless there's an actionable item. I believe I answered the original question. Thanks!
@jasongregori commented on GitHub (Mar 15, 2013):
Thanks @Haacked, it made sense to me, I was just looking for a confirmation from someone with authority.