mirror of
https://github.com/semver/semver.git
synced 2026-07-11 09:22:32 -05:00
[GH-ISSUE #832] Clarifying Lexical Comparison for Identifier Precedence #1410
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 @Andrei15193 on GitHub (May 5, 2022).
Original GitHub issue: https://github.com/semver/semver/issues/832
Hi,
In the specifications it is mentioned that precedence between identifiers that are not made out of digits (not numbers, basically) is determined by lexical comparison, however I am unsure how this applies to an edge case where one identifier is in the beginning of another identifier. For instance, if I have
1.0.0-alphaand1.0.0-alpha-prep, which one has precedence? Is it1.0.0-alpha < 1.0.0-alpha-prepor1.0.0-alpha-prep < 1.0.0-alpha?Please include a case like this in the precedence example on the landing page, just for clarification.
Thanks!
@jwdonahue commented on GitHub (May 11, 2022):
See 11.4.4:
@Andrei15193 commented on GitHub (May 11, 2022):
But in this case the set of pre-release fields is the same size. The pre-release identifiers are
alphaandalpha-prep. We can use a different example,1.0.0-alphaand1.0.0-alphaPrep, which one has precedence in this case?alphaoralphaPrep?@jwdonahue commented on GitHub (May 11, 2022):
Oh sorry. Alpha-prep is not two fields, my bad. The longer string is greater than the shorter one where they share a common prefix, so -alpha < -alphaPrep.
Standard lexical comparison. The standard libraries or built in string operators of every 3G language applies the same rules. The algorithm is more than a hundred years old.
a < b < ab < c
@Andrei15193 commented on GitHub (May 11, 2022):
Was guessing that it's like that, but wanted to make sure.
Alright, that clarifies it for me, thank you 😃
@jwdonahue commented on GitHub (May 11, 2022):
It gets way more complicated with unicode and semantically equivalent, but different codes. Hence the ASCII restriction.
@jwdonahue commented on GitHub (May 11, 2022):
@Andrei15193 Apologies for the confusion. I must have been more tired last night than I thought.
a < b < ab < cis incorrect.I thought I fixed it, but apparently made the same mistake twice. Good thing I skimmed my emails this morning. I have edited the original, and to be clear it should have been:
a < b < ba < c
Just like in a dictionary.
@Andrei15193 commented on GitHub (May 11, 2022):
Oh, I totally missed that, I was too focused on the
a < abcomparison. Thanks for looking it up! I've edited the comments and removed the quotes.