Skip to content

Commit

Permalink
fix: versioned route matching should not throw TypeError (#1381)
Browse files Browse the repository at this point in the history
  • Loading branch information
kusor authored and William Blankenship committed Jul 28, 2017
1 parent a2f0638 commit 25d10f0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/router.js
Expand Up @@ -509,7 +509,7 @@ Router.prototype.find = function find(req, res, callback) {
var v = semver.maxSatisfying(k, req.version());

if (v) {
if (!r || semver.gt(v, maxV)) {
if (!r || !maxV || semver.gt(v, maxV)) {
r = c.r;
params = c.p;
maxV = v;
Expand Down
35 changes: 35 additions & 0 deletions test/server.test.js
Expand Up @@ -1169,6 +1169,41 @@ test('versioned route matching should prefer \
});


test('versioned route matching should not throw TypeError' , function (t) {
var p = '/path/' + uuid.v4();

SERVER.post({
path: p,
version: ['1.1.0', '1.2.0'],
contentType: 'application/json'
}, function (req, res, next) {
res.json(200, {route: p});
next();
});

SERVER.post({
path: '/path/:id',
version: ['1.1.0', '1.2.0']
}, function (req, res, next) {
res.json(200, {route: 'id'});
next();
});

var opts = {
path: p,
headers: {
'accept-version': '~1'
}
};

CLIENT.post(opts, function (err, _, res, obj) {
t.equal(obj.route, p);
t.end();
});

});


test('GH-959 matchedVersion() should return on cached routes', function (t) {

SERVER.get({
Expand Down

0 comments on commit 25d10f0

Please sign in to comment.