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] Invalid falsey response when checking range is subset of any #374

Closed
jameschensmith opened this issue Mar 18, 2021 · 0 comments
Closed

Comments

@jameschensmith
Copy link
Contributor

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

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

Successfully merging a pull request may close this issue.

2 participants