Skip to content

Compare version number with rc is incorrect #38

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

Open
shuyingz opened this issue Sep 19, 2019 · 6 comments
Open

Compare version number with rc is incorrect #38

shuyingz opened this issue Sep 19, 2019 · 6 comments

Comments

@shuyingz
Copy link

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 shuyingz changed the title Compare version number with rc is wired Compare version number with rc is wrong Sep 19, 2019
@shuyingz shuyingz changed the title Compare version number with rc is wrong Compare version number with rc is incorrect Sep 19, 2019
@vdurmont
Copy link
Owner

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

@shuyingz
Copy link
Author

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)

@vdurmont
Copy link
Owner

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

@shuyingz
Copy link
Author

shuyingz commented Sep 19, 2019

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
Copy link
Author

Hi @vdurmont, any ideas about the comparison issue?

@piotrooo
Copy link

@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

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

3 participants