Skip to content

Commit

Permalink
fix(subset): check any as superset
Browse files Browse the repository at this point in the history
Adds short-circuit check if superset is `*`.

PR-URL: #375
Credit: @jameschensmith
Close: #375
Reviewed-by: @isaacs
  • Loading branch information
James Chen-Smith authored and isaacs committed Mar 22, 2021
1 parent 093b40f commit 15ed208
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ranges/subset.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const compare = require('../functions/compare.js')
// - Every simple range `r1, r2, ...` is a subset of some `R1, R2, ...`
//
// Simple range `c1 c2 ...` is a subset of simple range `C1 C2 ...` iff:
// - If C is only the ANY comparator
// - return true
// - If c is only the ANY comparator
// - If C is only the ANY comparator, return true
// - Else return false
Expand Down Expand Up @@ -58,6 +60,9 @@ const simpleSubset = (sub, dom, options) => {
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

Expand Down
6 changes: 6 additions & 0 deletions test/ranges/subset.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ const cases = [
['>2 <1', '3', true],
['1 || 2 || 3', '>=1.0.0', true],

// everything is a subset of *
['1.2.3', '*', true],
['^1.2.3', '*', true],
['^1.2.3-pre.0', '*', true],
['1 || 2 || 3', '*', true],

['*', '*', true],
['', '*', true],
['*', '', true],
Expand Down

0 comments on commit 15ed208

Please sign in to comment.