Browse files

Correct maxSatisfying

Was using the wrong compare in the sort function.

Closes #35
  • Loading branch information...
1 parent c2c6d24 commit 432f0f58822d1a7572220a09a97f2708270cc750 @isaacs isaacs committed Jun 24, 2013
Showing with 16 additions and 1 deletion.
  1. +1 −1 semver.js
  2. +15 −0 test/index.js
View
2 semver.js
@@ -835,7 +835,7 @@ exports.maxSatisfying = maxSatisfying;
function maxSatisfying(versions, range, loose) {
return versions.filter(function(version) {
return satisfies(version, range, loose);
- }).sort(compare)[0] || null;
+ }).sort(rcompare)[0] || null;
}
exports.validRange = validRange;
View
15 test/index.js
@@ -514,3 +514,18 @@ test('\nstrict vs loose ranges', function(t) {
});
t.end();
});
+
+test('\nmax satisfying', function(t) {
+ [[['1.2.3', '1.2.4'], '1.2', '1.2.4'],
+ [['1.2.4', '1.2.3'], '1.2', '1.2.4'],
+ [['1.2.3','1.2.4','1.2.5','1.2.6'], '~1.2.3', '1.2.6']
+ ].forEach(function(v) {
+ var versions = v[0];
+ var range = v[1];
+ var expect = v[2];
+ var loose = v[3];
+ var actual = semver.maxSatisfying(versions, range, loose);
+ t.equal(actual, expect);
+ });
+ t.end();
+});

2 comments on commit 432f0f5

@bminer

This commit appears to break things... what about version strings like: 3.0.0alpha1???

TypeError: Invalid Version: 3.0.0alpha1

@bminer

Actually... might not be this commit... just see issue #37.

Please sign in to comment.