Skip to content

[BUG] intersects(r1, r2, options) function returns true if the not intersected range < 0.0.0 and 0.x are supplied #521

Closed
@sounisi5011

Description

@sounisi5011

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Range < 0.0.0 (or range < 0.0.0-0 if the includePrerelease option is true) should not intersect with all ranges. However, the intersects(r1, r2, options) function returns true when comparing ranges < 0.0.0 (< 0.0.0-0) and X-Range.

Expected Behavior

  • Returns false if compared to range < 0.0.0 if the includePrerelease option is false
  • Returns false if compared to range < 0.0.0-0 if the includePrerelease option is true

Steps To Reproduce

const semver = require('semver'); // Import [email protected]

// This returns `false`, which is as expected since the two ranges do not intersect
semver.intersects('< 1.0.0', '1.0.0', { includePrerelease: false }) === false

// These also return `false`
semver.intersects('< 1.0.0', '1.x', { includePrerelease: false }) === false
semver.intersects('< 0.0.0', '1.x', { includePrerelease: false }) === false
semver.intersects('< 0.0.0', '0.1.x', { includePrerelease: false }) === false
semver.intersects('< 0.0.0', '0.0.0', { includePrerelease: false }) === false

// These return `true` because they intersect if a pre-release is included
semver.intersects('< 1.0.0', '1.x', { includePrerelease: true }) === true
semver.intersects('< 0.0.0', '0.x', { includePrerelease: true }) === true

// However, when compared to the X-Range, this returns `true` instead of `false`
semver.intersects('< 0.0.0', '0.0.x', { includePrerelease: false }) !== false
semver.intersects('< 0.0.0', '0.x', { includePrerelease: false }) !== false
semver.intersects('< 0.0.0', '0', { includePrerelease: false }) !== false
semver.intersects('< 0.0.0-0', '0.0.x', { includePrerelease: true }) !== false
semver.intersects('< 0.0.0-0', '0.x', { includePrerelease: true }) !== false
semver.intersects('< 0.0.0-0', '0', { includePrerelease: true }) !== false

// Whether the range `< 0.0.0` is an X-range or not does not affect the result
semver.intersects('< 0', '0.0.0', { includePrerelease: false }) === false
semver.intersects('< 0.x', '0.0.0', { includePrerelease: false }) === false
semver.intersects('< 0.0.x', '0.0.0', { includePrerelease: false }) === false
semver.intersects('< 0', '0.0.x', { includePrerelease: false }) !== false
semver.intersects('< 0.x', '0.0.x', { includePrerelease: false }) !== false
semver.intersects('< 0.0.x', '0.0.x', { includePrerelease: false }) !== false

Environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingPriority 1high priority issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions