semver4j icon indicating copy to clipboard operation
semver4j copied to clipboard

Is this correct behaviour when comparing versions

Open aslak-dirdal opened this issue 6 years ago • 8 comments

Using

compile 'com.vdurmont:semver4j:2.0.3'

Semver A = new Semver("2.0", Semver.SemverType.LOOSE); Semver B = new Semver("2.0.0", Semver.SemverType.LOOSE); A.isGreaterThan(B); // -> false B.isGreaterThan(A); // -> false B.isEquivalentTo(A); // -> false A.isEquivalentTo(B); // -> false B.isLowerThan(A); // -> true A.isLowerThan(B); // -> true

aslak-dirdal avatar Aug 08 '17 08:08 aslak-dirdal

Yes, I'm hitting the same issue. The library doesn't know how to compare correctly when comparing versions that don't have the same version type. e.g.: "MAJOR" vs "MAJOR.MINOR.PATCH"

gihad avatar Sep 29 '17 20:09 gihad

I believe this should have been fixed by my PR https://github.com/vdurmont/semver4j/pull/20. Mind giving it a try?

sschuberth avatar Dec 13 '17 20:12 sschuberth

I still get

new Semver("2", SemverType.LOOSE).isEqualTo("2.0") // false

nomaed avatar Oct 02 '18 17:10 nomaed

I actually had to do a fixup in PR https://github.com/vdurmont/semver4j/pull/25, which is not in a released version yet. That should fix it.

Edit: No, it doesn't. Hmpf.

sschuberth avatar Oct 02 '18 17:10 sschuberth

I worked around it by adding a helper function that converts everything .toStrict(), so

    private Semver version(String versionString) {
        return new Semver(versionString, SemverType.LOOSE).toStrict();
    }

//////

version("2").isEqualTo(version("2.0")) // true

But I don't like this workaround ;)

nomaed avatar Oct 02 '18 17:10 nomaed

I assume this is another variant of this: new Semver("123", SemverType.NPM).satisfies("123") == false

collinpeters avatar Jan 13 '20 23:01 collinpeters

This is still an issue.

// should be true BUT IS FALSE
new Semver("2.0", Semver.SemverType.LOOSE).isGreaterThanOrEqualTo("2.0.0");

// should be true BUT IS FALSE
new Semver("2.0", Semver.SemverType.LOOSE).isEqualTo("2.0.0");

// should be true BUT IS FALSE
new Semver("2.0.0", Semver.SemverType.STRICT).isGreaterThanOrEqualTo(new Semver("2.0", Semver.SemverType.LOOSE));

mvdobrinin avatar Jul 13 '21 00:07 mvdobrinin

@aslak-dirdal 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