semver4j
semver4j copied to clipboard
Compare version number with rc is incorrect
Hi,
Hope you are doing well!
I am wondering if semver supports version with rc without a dot (.) - exp: 1.0.0-rc1
I have two version numbers - 1.0.0-rc3 and 1.0.0-rc11, and for the current lib, when I am trying to compare these two versions, it shown me that 1.0.0-rc3 > 1.0.0-rc11 but which is not making any sense to me.
Semver sem1 = new Semver("1.0.0-rc3", Semver.SemverType.LOOSE);
Semver sem2 = new Semver("1.0.0-rc11", Semver.SemverType.LOOSE);
System.out.println(sem1.isGreaterThan(sem2)); // --- which is true
Can anybody please help?
Thanks!
I didn't check, but I think we compare the "rc3" and "rc11" using a string comparison. We don't compare the numbers themselves :(
yeah.. I just checked in the code and that's the reason why rc3 is greater than rc11.
May I create a PR fix that issue..? (If that is consider as an issue)
Yeah definitely! Maybe just check the behavior on the original semver library (the npm one) to make sure they’re doing it too?
Interesting thing... I checked the behavior on the npm semver and here is the result...
const semver = require('semver')
semver.compare('1.0.0-rc11', '1.0.0-rc3') // ---- return -1
Above means rc11 is smaller than rc3. I think the npm also probably using the string comparison, but anyway I created a PR for that. Please let me know what you are thinking.
Hi @vdurmont, any ideas about the comparison issue?
@shuyingz if you are still interesting, I've made copy of this lib and fix bug reported by you. Look for version 2.0.1