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-alpha and 1.0.0-alpha-prep, which one has precedence? Is it 1.0.0-alpha < 1.0.0-alpha-prep or 1.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!
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-alpha` and `1.0.0-alpha-prep`, which one has precedence? Is it `1.0.0-alpha < 1.0.0-alpha-prep` or `1.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!
A larger set of pre-release fields has a higher precedence than a smaller set, if all of the preceding identifiers are equal
<!-- gh-comment-id:1123201832 -->
@jwdonahue commented on GitHub (May 11, 2022):
See [11.4.4](https://semver.org/#spec-item-11):
> A larger set of pre-release fields has a higher precedence than a smaller set, if all of the preceding identifiers are equal
But in this case the set of pre-release fields is the same size. The pre-release identifiers are alpha and alpha-prep. We can use a different example, 1.0.0-alpha and 1.0.0-alphaPrep, which one has precedence in this case? alpha or alphaPrep?
<!-- gh-comment-id:1123219219 -->
@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 `alpha` and `alpha-prep`. We can use a different example, `1.0.0-alpha` and `1.0.0-alphaPrep`, which one has precedence in this case? `alpha` or `alphaPrep`?
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
<!-- gh-comment-id:1123237960 -->
@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](https://www.cplusplus.com/reference/algorithm/lexicographical_compare/#:~:text=A%20lexicographical%20comparison%20is%20the,not%20equivalent%20to%20the%20other.). 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
Was guessing that it's like that, but wanted to make sure.
Alright, that clarifies it for me, thank you 😃
<!-- gh-comment-id:1123244412 -->
@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 😃
It gets way more complicated with unicode and semantically equivalent, but different codes. Hence the ASCII restriction.
<!-- gh-comment-id:1123246992 -->
@jwdonahue commented on GitHub (May 11, 2022):
It gets way more complicated with unicode and semantically equivalent, but different codes. Hence the ASCII restriction.
@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.
<!-- gh-comment-id:1123993911 -->
@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 < c` **is 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.
Oh, I totally missed that, I was too focused on the a < ab comparison. Thanks for looking it up! I've edited the comments and removed the quotes.
<!-- gh-comment-id:1124056689 -->
@Andrei15193 commented on GitHub (May 11, 2022):
Oh, I totally missed that, I was too focused on the `a < ab` comparison. Thanks for looking it up! I've edited the comments and removed the quotes.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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.