Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-1380 versioned route matching should not throw TypeError #1381

Merged
merged 5 commits into from Jul 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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