Skip to content

Commit 15ed208

Browse files
James Chen-Smithisaacs
James Chen-Smith
authored andcommittedMar 22, 2021
fix(subset): check any as superset
Adds short-circuit check if superset is `*`. PR-URL: #375 Credit: @jameschensmith Close: #375 Reviewed-by: @isaacs
1 parent 093b40f commit 15ed208

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed
 

‎ranges/subset.js

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const compare = require('../functions/compare.js')
77
// - Every simple range `r1, r2, ...` is a subset of some `R1, R2, ...`
88
//
99
// Simple range `c1 c2 ...` is a subset of simple range `C1 C2 ...` iff:
10+
// - If C is only the ANY comparator
11+
// - return true
1012
// - If c is only the ANY comparator
1113
// - If C is only the ANY comparator, return true
1214
// - Else return false
@@ -58,6 +60,9 @@ const simpleSubset = (sub, dom, options) => {
5860
if (sub === dom)
5961
return true
6062

63+
if (dom.length === 1 && dom[0].semver === ANY)
64+
return true
65+
6166
if (sub.length === 1 && sub[0].semver === ANY)
6267
return dom.length === 1 && dom[0].semver === ANY
6368

‎test/ranges/subset.js

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ const cases = [
1515
['>2 <1', '3', true],
1616
['1 || 2 || 3', '>=1.0.0', true],
1717

18+
// everything is a subset of *
19+
['1.2.3', '*', true],
20+
['^1.2.3', '*', true],
21+
['^1.2.3-pre.0', '*', true],
22+
['1 || 2 || 3', '*', true],
23+
1824
['*', '*', true],
1925
['', '*', true],
2026
['*', '', true],

0 commit comments

Comments
 (0)
Please sign in to comment.