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

[BUG] inc affects the inputed SemVer object. #425

Closed
louis-bompart opened this issue Jan 28, 2022 · 0 comments · Fixed by #427
Closed

[BUG] inc affects the inputed SemVer object. #425

louis-bompart opened this issue Jan 28, 2022 · 0 comments · Fixed by #427
Labels
Bug thing that needs fixing

Comments

@louis-bompart
Copy link
Contributor

louis-bompart commented Jan 28, 2022

What / Why

inc when called with an instance of SemVer will affect the provided SemVer object (if no opts are given, see Steps to Reproduce). This leads to unexpected behaviour for a function that could be expected to be pure.

When

  • n/a

Where

  • n/a

How

Current Behavior

inc will do the operation on the SemVer object provided in parameters, except if semver is created with loose or includePrereleaseSemVer.

Steps to Reproduce

const { SemVer, inc } = require("semver");
const { equal } = require("assert");

const initalStrVer = "1.0.0";
const initialSemver = new SemVer(initalStrVer);
const looseSemver = new SemVer(initalStrVer, { loose: true });
const includePrereleaseSemVer = new SemVer(initalStrVer, {
  includePrerelease: true,
});

inc(initialSemver, "minor");
inc(looseSemver, "minor");
inc(includePrereleaseSemVer, "minor");
inc(initalStrVer, "minor");

equal(initalStrVer, looseSemver.version); // ✔️  Pass
equal(initalStrVer, includePrereleaseSemVer.version); // ✔️ Pass
equal(initalStrVer, initialSemver.version); // ❌ AssertionError [ERR_ASSERTION]: '1.0.0' == '1.1.0'

Expected Behavior

inc should never modify the provided SemVer object.

Who

  • n/a

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants