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

Compare versions without patch level returns unexpected results #59

Open
npitch opened this issue Aug 27, 2021 · 1 comment
Open

Compare versions without patch level returns unexpected results #59

npitch opened this issue Aug 27, 2021 · 1 comment

Comments

@npitch
Copy link

npitch commented Aug 27, 2021

 >=1.100 satisfied by 1.2.0 : false
 1.2.0 satisfies >=1.100 : true
 1.2.0 isEqual 1.100 : true
 1.100 isEqual 1.2.0 : false

This is the result from executing the following code:

public static void main(String[] args) {
        String requirement = ">=1.100";
        String version = "1.2.0";

        Requirement r = Requirement.buildNPM(requirement);
        boolean satisfiedBy = r.isSatisfiedBy(version);
        System.out.println(String.format(" %s satisfied by %s : %s", r, version, satisfiedBy));

        boolean satisfies = new Semver(version, SemverType.NPM).satisfies(requirement);
        System.out.println(String.format(" %s satisfies %s : %s", version, requirement, satisfies));

        String v1 = "1.2.0";
        String v2 = "1.100";
        boolean isEqualV1V2 = new Semver(v1, SemverType.NPM).isEqualTo(new Semver(v2, SemverType.NPM));
        System.out.println(String.format(" %s isEqual %s : %s", v1, v2, isEqualV1V2));

        boolean isEqualV2V1 = new Semver(v2, SemverType.NPM).isEqualTo(new Semver(v1, SemverType.NPM));
        System.out.println(String.format(" %s isEqual %s : %s", v2, v1, isEqualV2V1));

    } 

and one of the bugs is in the following code:
Semver#isEqualTo

        if (this.type == SemverType.NPM) {
            if (this.getMajor() != version.getMajor()) return false;
            if (version.getMinor() == null) return true;
            if (version.getPatch() == null) return true;
        }

if (version.getPatch() == null) return true;

@npitch npitch changed the title Compare versions without patch version returns unexpected results Compare versions without patch level returns unexpected results Aug 27, 2021
@piotrooo
Copy link

@npitch 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

2 participants