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

Bugfix #1793

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Bugfix #1793

wants to merge 1 commit into from

Conversation

carlosascari
Copy link

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:

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
      })
    }
  }
]));

Pre-Submission Checklist

  • Opened an issue discussing these changes before opening the PR
  • Ran the linter and tests via make prepush
  • Included comprehensive and convincing tests for changes

Issues

Closes:

  • Issue #
  • Issue #
  • Issue #

Summarize the issues that discussed these changes

Changes

What does this PR do?

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
      })
    }
  }
]));
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant