Skip to content

Commit

Permalink
Correct maxSatisfying
Browse files Browse the repository at this point in the history
Was using the wrong compare in the sort function.

Closes #35
  • Loading branch information
isaacs committed Jun 24, 2013
1 parent c2c6d24 commit 432f0f5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion semver.js
Expand Up @@ -835,7 +835,7 @@ exports.maxSatisfying = maxSatisfying;
function maxSatisfying(versions, range, loose) { function maxSatisfying(versions, range, loose) {
return versions.filter(function(version) { return versions.filter(function(version) {
return satisfies(version, range, loose); return satisfies(version, range, loose);
}).sort(compare)[0] || null; }).sort(rcompare)[0] || null;
} }


exports.validRange = validRange; exports.validRange = validRange;
Expand Down
15 changes: 15 additions & 0 deletions test/index.js
Expand Up @@ -514,3 +514,18 @@ test('\nstrict vs loose ranges', function(t) {
}); });
t.end(); 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
Copy link

@bminer bminer commented on 432f0f5 Jul 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

TypeError: Invalid Version: 3.0.0alpha1

@bminer
Copy link

@bminer bminer commented on 432f0f5 Jul 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.