Skip to content

[BUG] semver.lt returns wrong value for pre-release version comparison #483

Open
@IainSAP

Description

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

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions