From 1e625f0ae1d23aaa42725d5e925381dfdfeb85a5 Mon Sep 17 00:00:00 2001 From: James Chen-Smith Date: Wed, 17 Mar 2021 21:01:50 -0500 Subject: [PATCH] fix(subset): check any as superset Adds short-circuit check if superset is `*`. --- ranges/subset.js | 5 +++++ test/ranges/subset.js | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/ranges/subset.js b/ranges/subset.js index bb7d15fe..42a2552f 100644 --- a/ranges/subset.js +++ b/ranges/subset.js @@ -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 @@ -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 diff --git a/test/ranges/subset.js b/test/ranges/subset.js index a16a21d2..368bcc21 100644 --- a/test/ranges/subset.js +++ b/test/ranges/subset.js @@ -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],