Skip to content

Commit 9fb2c19

Browse files
committed
Exclude prereleases in X-ranges with < comparators
This one didn't cause any bugs, but it's more for consistency and future-proofing. When a range like '<=1' is translated to 'anything less than 2.0.0', it should be expressed as '<2.0.0-0' to prevent prerelease 2.0.0 versions as well. It didn't cause any problems with intersection or range satisfying because it would only treat 2.0.0-pre as satisfying <2.0.0 when includePrerelease was set, and if includePrerelease was set, then it would add the -0 to the less-than comparator. Nevertheless, all other areas where we use a <X.Y.0 range, we add the -0 prerelease in order to force the boundary of the set to exclude prereleases on that version, which is good defense in depth to prevent other errors with intersection and subsets seen previously.
1 parent b97044b commit 9fb2c19

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

classes/range.js

+3
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@ const replaceXRange = (comp, options) => {
358358
}
359359
}
360360

361+
if (gtlt === '<')
362+
pr = '-0'
363+
361364
ret = `${gtlt + M}.${m}.${p}${pr}`
362365
} else if (xm) {
363366
ret = `>=${M}.0.0${pr} <${+M + 1}.0.0-0`

test/fixtures/range-parse.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ module.exports = [
6868
['^0.1.2', '>=0.1.2 <0.2.0-0'],
6969
['^1.2.3', '>=1.2.3 <2.0.0-0'],
7070
['^1.2.3-beta.4', '>=1.2.3-beta.4 <2.0.0-0'],
71-
['<1', '<1.0.0'],
72-
['< 1', '<1.0.0'],
71+
['<1', '<1.0.0-0'],
72+
['< 1', '<1.0.0-0'],
7373
['>=1', '>=1.0.0'],
7474
['>= 1', '>=1.0.0'],
75-
['<1.2', '<1.2.0'],
76-
['< 1.2', '<1.2.0'],
75+
['<1.2', '<1.2.0-0'],
76+
['< 1.2', '<1.2.0-0'],
7777
['1', '>=1.0.0 <2.0.0-0'],
7878
['>01.02.03', '>1.2.3', true],
7979
['>01.02.03', null],

test/ranges/to-comparators.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ test('comparators test', (t) => {
6060
['~ 1.0', [['>=1.0.0', '<1.1.0-0']]],
6161
['~ 1.0.3', [['>=1.0.3', '<1.1.0-0']]],
6262
['~> 1.0.3', [['>=1.0.3', '<1.1.0-0']]],
63-
['<1', [['<1.0.0']]],
64-
['< 1', [['<1.0.0']]],
63+
['<1', [['<1.0.0-0']]],
64+
['< 1', [['<1.0.0-0']]],
6565
['>=1', [['>=1.0.0']]],
6666
['>= 1', [['>=1.0.0']]],
67-
['<1.2', [['<1.2.0']]],
68-
['< 1.2', [['<1.2.0']]],
67+
['<1.2', [['<1.2.0-0']]],
68+
['< 1.2', [['<1.2.0-0']]],
6969
['1', [['>=1.0.0', '<2.0.0-0']]],
7070
['1 2', [['>=1.0.0', '<2.0.0-0', '>=2.0.0', '<3.0.0-0']]],
7171
['1.2 - 3.4.5', [['>=1.2.0', '<=3.4.5']]],

0 commit comments

Comments
 (0)