Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions classes/comparator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/comparator-intersection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/range-intersection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
]