From f470157c8d8304d3d730104f1b4a72e40d45baba Mon Sep 17 00:00:00 2001 From: Ascari Date: Mon, 24 Jun 2019 11:51:04 -0500 Subject: [PATCH] Bugfix When using the **conditionalHandler** plugin, if a single version route has a `contentType`, but the other routes do not, it will crash as it tries to call `.join` on a undefined `contentType` field. See for yourself: ``` bug.js const restify = require('restify'); const server = restify.createServer(); server.get('/', restify.plugins.conditionalHandler([ { contentType: ['application/json'], version: '1.5.0', handler: (req, res, next) => { res.json({ version: 0 }) } }, { // contentType is missing here version: '1.1.0', handler: (req, res, next) => { res.json({ version: 1 }) } } ])); ``` --- lib/plugins/conditionalHandler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/conditionalHandler.js b/lib/plugins/conditionalHandler.js index 7ddf55c1b..f2108c442 100644 --- a/lib/plugins/conditionalHandler.js +++ b/lib/plugins/conditionalHandler.js @@ -126,7 +126,7 @@ function conditionalHandler(candidates) { reqCandidates = candidates.filter(function filter(candidate) { var neg = new Negotiator({ headers: { - accept: candidate.contentType.join(', ') + accept: (candidate.contentType) ? candidate.contentType.join(', ') : '' } }); var tmp = neg.preferredMediaType(contentTypes);