New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarifying Lexical Comparison for Identifier Precedence (Again) #970
Comments
I think so, yes. 11.4 is the relevant section:
So the prerelease version will be split into the identifiers like so (written as python arrays and python strings): The comparisons would therefore be:
The second comparison will never be reached because "alpha" takes precedence over 1 (section 11.4.3) |
So first we have #9:
Then there's #11:
Fortunately, the ASCII codes for the digits [0..9] are lower than the codes for [a..z] and [A..Z], so as long as your string consists of ASCII or UTF-8 characters in those character ranges, you can simply compare each character of each field from left to right until you encounter a character that is greater, or the field has more characters. So: 'a' > '1' (ie; 97 > 49), and your done. So there's no need to ever convert a numeric identifier to a scaler like int or long, it's just wasteful. I do always split the string on the dots and make sure the first three fields are pure numeric characters and the remaining fields are in the expected character ranges, before doing any comparisons. While not explicitly stated in the spec, the SemVer rules do not apply to non-SemVer strings. Such comparisons require consideration of implicit and explicit semantics, if any, of the non-SemVer string and may also require attention to cultures. See also: |
I've looked at #832 and #561, and I'm still not sure how to resolve a comparison like
1.0.0-alpha.1
1.0.0-1.alpha
Is it safe to assume that the comparison here will be alphanumeric, even though one field in each comparison is numeric?
The text was updated successfully, but these errors were encountered: