Skip to content

[BUG] Invalid falsey response when checking range is subset of any #374

Closed
@jameschensmith

Description

@jameschensmith

What / Why

I've run into an interesting issue when submitting a PR for npm's arborist library, where a range (e.g. ~3.5.0) is not a subset of any. This should be supported, as even though any is not a subset of a range (which is already handled), the opposite is not the case.

I think the fix would be to add an additional short-circuit check in lines 58-62 (v7.3.4 snippet) to handle an any dom value:

  if (sub === dom)
    return true

+  if (dom.length === 1 && dom[0].semver === ANY)
+    return true

  if (sub.length === 1 && sub[0].semver === ANY)
    return dom.length === 1 && dom[0].semver === ANY

When

I run a subset comparison for if a given range is a subset of any

Example

const semver = require("semver");
// ~3.5.0 := >=3.5.0 <3.(5+1).0 := >=3.5.0 <3.6.0-0
console.log(semver.subset("~3.5.0", "*"));
// false

Current Behavior

Result is falsey.

Expected Behavior

Result should be truthy, as >=3.5.0 <3.6.0-0 should be a subset of any.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions