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] semver.lt returns wrong value for pre-release version comparison #483

Open
1 task done
Tracked by #501
IainSAP opened this issue Sep 22, 2022 · 3 comments
Open
1 task done
Tracked by #501
Labels
Bug thing that needs fixing

Comments

@IainSAP
Copy link

IainSAP commented Sep 22, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Using semver.lt() returns the incorrect value when comparing pre-release version with includePrerelease set to false (or the default).

image

By comparison, explicitly coercing you get:

semver_1.lt(semver_1.coerce('0.2.0-1'), minVersion)
false

My assumption is that strings are implicitly coerced when calling comparison functions, perhaps this is incorrect?

Expected Behavior

semver.lt('0.2.0-1', '0.2.0', { includePrerelease: false }) should return false.

Steps To Reproduce

  1. In node shell
  2. With the current latest version of semver installed
  3. Run 'require('semver').lt('0.2.0-1', '0.2.0', { includePrerelease: false })
  4. Wrong value true is returned

Environment

  • npm: 6.14.15
  • Node: 14.8.1
  • OS: Mac Monterey 12.5.1
  • platform: Macbook Pro i9
@IainSAP IainSAP added Bug thing that needs fixing Needs Triage needs an initial review labels Sep 22, 2022
@IainSAP IainSAP changed the title [BUG] <title> [BUG] semver.lt returns wrong value for pre-release version comparison Sep 22, 2022
@lukekarrys
Copy link
Contributor

This is similar to #345, and I think the fix might even be the same for both.

@lukekarrys lukekarrys removed the Needs Triage needs an initial review label Oct 27, 2022
@wraithgar wraithgar mentioned this issue Apr 17, 2023
14 tasks
@mbtools
Copy link
Contributor

mbtools commented Jan 21, 2025

The comparison functions do not use the includePrerelease option! If major.minor.patch are the same, they always compare the pre-release parts.

Maybe the docs could be improved since it's suggesting that all functions use evaluate all options:

node-semver/README.md

Lines 402 to 414 in 868d4bb

All methods and classes take a final `options` object argument. All
options in this object are `false` by default. The options supported
are:
- `loose`: Be more forgiving about not-quite-valid semver strings.
(Any resulting output will always be 100% strict compliant, of
course.) For backwards compatibility reasons, if the `options`
argument is a boolean value instead of an object, it is interpreted
to be the `loose` param.
- `includePrerelease`: Set to suppress the [default
behavior](https://github.com/npm/node-semver#prerelease-tags) of
excluding prerelease tagged versions from ranges unless they are
explicitly opted into.

@6Demon6Child6
Copy link

6Demon6Child6 commented Jan 21, 2025 via email

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

No branches or pull requests

4 participants