Skip to content

Commit 15ed208

Browse files
James Chen-Smithisaacs
authored andcommitted
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy