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

Are semver comparisons broken in this library? #1

Open
peffis opened this issue Oct 17, 2019 · 2 comments
Open

Are semver comparisons broken in this library? #1

peffis opened this issue Oct 17, 2019 · 2 comments

Comments

@peffis
Copy link

peffis commented Oct 17, 2019

> semver:compare(semver:parse(<<"1.0.10">>), semver:parse(<<"1.0.9">>)).
-1
> semver:compare(semver:parse(<<"1.0.9">>), semver:parse(<<"1.0.8">>)).
1

Should not 1.0.10 be larger than 1.0.9, like how 1.0.9 is larger than 1.0.8?

@peffis
Copy link
Author

peffis commented Oct 17, 2019

Yes, it's broken. The unpack function makes some float out of the semver, like so:

unpack({semver,1,0,10,undefined}).
1.01

This does not work if you compare against, say a semver of 1.0.9 which results in 1.09.

A better comparison would be to not go the extra mile and converting to a float - just comparing the records as they are would work better so skip the unpack step and just do
{semver,1,0,10,undefined} > {semver,1,0,9,undefined} and so on...removes a bit of code also from the library...

@peffis
Copy link
Author

peffis commented Oct 17, 2019

I'm happy to do a PR of peffis@c25d025 if you are interested...

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