Skip to content
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

Why 1.0.0-alpha-9.9A < 1.0.0-alpha-9.10A is true #76

Open
xflcx1991 opened this issue Sep 2, 2024 · 2 comments
Open

Why 1.0.0-alpha-9.9A < 1.0.0-alpha-9.10A is true #76

xflcx1991 opened this issue Sep 2, 2024 · 2 comments

Comments

@xflcx1991
Copy link

xflcx1991 commented Sep 2, 2024

compare-versions,6.1.1
According to https://semver.org/, dot-separated identifiers with letters or hyphens are sorted by ASCII values
Then 1.0.0-alpha-9.9A and 1.0.0-alpha-9.10A should be sorted by ASCII with "9A" and "10A", the first character '9' > '1',so it should be "1.0.0-alpha-9.9A" greater than "1.0.0-alpha-9.10A", but the result is the opposite.

But if changed to "1.0.0-alpha-9. A9A" and "1.0.0-alpha-9. A10A", "1.0.0-alpha-9. A9A" is bigger.

It seems that if a dot-separated identifier is prefixed with a number, compare-versions will be compared numerically, which does not meet the rule of "Identifiers with letters or hyphens are compared lexically in ASCII sort order".

@xflcx1991
Copy link
Author

I used npm install --save semver and it strictly followed the rules, please see

console.log(compareVersions('1.0.0-alpha-9.9A', '1.0.0-alpha-9.10A'))
console.log(semver.gt('1.0.0-alpha-9.9A', '1.0.0-alpha-9.10A'))
console.log('-------------------------------')
console.log(compareVersions('1.0.0-alpha-9.A9A', '1.0.0-alpha-9.A10A'))
console.log(semver.gt('1.0.0-alpha-9.A9A', '1.0.0-alpha-9.A10A'))

output

-1
true
----------------------------------
1
true

So is it a problem?

@xflcx1991
Copy link
Author

Another example of different results from the semver library:

console.log(compareVersions('10.2.2-rc.19', '10.2.2-rc.1a')) // 10.2.2-rc.19 > 10.2.2-rc.1a
console.log(semver.lt('10.2.2-rc.19', '10.2.2-rc.1a'))  // but semver says 10.2.2-rc.19 < 10.2.2-rc.1a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant