diff --git a/classes/comparator.js b/classes/comparator.js index 647c1f09..545c46f0 100644 --- a/classes/comparator.js +++ b/classes/comparator.js @@ -81,15 +81,9 @@ class Comparator { throw new TypeError('a Comparator is required') } - if (this.operator === '') { - if (this.value === '') { - return true - } + if (this.operator === '' && this.value !== '') { return new Range(comp.value, options).test(this.value) - } else if (comp.operator === '') { - if (comp.value === '') { - return true - } + } else if (comp.operator === '' && comp.value !== '') { return new Range(this.value, options).test(comp.semver) } @@ -105,6 +99,11 @@ class Comparator { return false } + // A wildcard intersects every non-empty range. + if (this.value === '' || comp.value === '') { + return true + } + // Same direction increasing (> or >=) if (this.operator.startsWith('>') && comp.operator.startsWith('>')) { return true diff --git a/test/fixtures/comparator-intersection.js b/test/fixtures/comparator-intersection.js index 08c4bc08..760fbb68 100644 --- a/test/fixtures/comparator-intersection.js +++ b/test/fixtures/comparator-intersection.js @@ -32,6 +32,17 @@ module.exports = [ ['>1.0.0', '<=2.0.0', true], ['<=2.0.0', '>1.0.0', true], ['<=1.0.0', '>=2.0.0', false], + // Empty ranges cannot intersect the wildcard, in either argument order. + ['', '<0.0.0', false], + ['', '<0.0.0-0', false], + ['', '<0.0.0-0', false, true], + ['', '<0.0.0', true, true], + ['', '<=0.0.0', true], + ['', '<0.0.1', true], + ['', '<0.0.0-alpha', false], + ['', '<0.0.0-alpha', true, true], + ['', '0.0.0-alpha', false], + ['', '0.0.0-alpha', true, true], ['', '', true], ['', '>1.0.0', true], ['<=2.0.0', '', true], diff --git a/test/fixtures/range-intersection.js b/test/fixtures/range-intersection.js index 217bee22..51bdf8ef 100644 --- a/test/fixtures/range-intersection.js +++ b/test/fixtures/range-intersection.js @@ -56,6 +56,11 @@ module.exports = [ ['x', '1.3.0 || <1.0.0 >2.0.0', true], ['1.3.0 || <1.0.0 >2.0.0', 'x', true], ['1.x', '1.3.0 || <1.0.0 >2.0.0', true], + ['*', '>*', false], + ['*', '<*', false], + ['*', '<0.0.0', false], + ['*', '<0.0.0-0', false], + ['*', '<0.0.0-0 || 1.x', true], ['*', '*', true], ['x', '', true], ]