Skip to content

Commit 7be83d1

Browse files
committed
Handle bad ranges in max/min satisfying
Fix #201
1 parent e1c49c8 commit 7be83d1

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

semver.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,11 @@ exports.maxSatisfying = maxSatisfying;
11531153
function maxSatisfying(versions, range, loose) {
11541154
var max = null;
11551155
var maxSV = null;
1156-
var rangeObj = new Range(range, loose);
1156+
try {
1157+
var rangeObj = new Range(range, loose);
1158+
} catch (er) {
1159+
return null;
1160+
}
11571161
versions.forEach(function (v) {
11581162
if (rangeObj.test(v)) { // satisfies(v, range, loose)
11591163
if (!max || maxSV.compare(v) === -1) { // compare(max, v, true)
@@ -1169,7 +1173,11 @@ exports.minSatisfying = minSatisfying;
11691173
function minSatisfying(versions, range, loose) {
11701174
var min = null;
11711175
var minSV = null;
1172-
var rangeObj = new Range(range, loose);
1176+
try {
1177+
var rangeObj = new Range(range, loose);
1178+
} catch (er) {
1179+
return null;
1180+
}
11731181
versions.forEach(function (v) {
11741182
if (rangeObj.test(v)) { // satisfies(v, range, loose)
11751183
if (!min || minSV.compare(v) === 1) { // compare(min, v, true)

test/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,3 +890,10 @@ test('sorting', function(t) {
890890
t.same(semver.rsort(list), rsorted);
891891
t.end();
892892
});
893+
894+
test('bad ranges in max/min satisfying', function(t) {
895+
var r = 'some frogs and sneks-v2.5.6';
896+
t.equal(semver.maxSatisfying([], r), null);
897+
t.equal(semver.minSatisfying([], r), null);
898+
t.end();
899+
});

0 commit comments

Comments
 (0)