semver4j icon indicating copy to clipboard operation
semver4j copied to clipboard

Compare version number with rc is incorrect

Open shuyingz opened this issue 6 years ago • 6 comments

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!

shuyingz avatar Sep 19 '19 14:09 shuyingz

I didn't check, but I think we compare the "rc3" and "rc11" using a string comparison. We don't compare the numbers themselves :(

vdurmont avatar Sep 19 '19 15:09 vdurmont

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)

shuyingz avatar Sep 19 '19 17:09 shuyingz

Yeah definitely! Maybe just check the behavior on the original semver library (the npm one) to make sure they’re doing it too?

vdurmont avatar Sep 19 '19 17:09 vdurmont

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.

shuyingz avatar Sep 19 '19 18:09 shuyingz

Hi @vdurmont, any ideas about the comparison issue?

shuyingz avatar Sep 25 '19 15:09 shuyingz

@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

piotrooo avatar Jul 22 '22 22:07 piotrooo