Skip to content

router.bind is overridden as an http method #41

@wesleytodd

Description

@wesleytodd

Not sure if this is a new things in node 6, I'm running 6.1.0, but the core http.methods include the http BIND method. When we loop the methods we end up overriding function.bind on the router instance causing weird behavior. The test that broke was as follows:

it('should reject missing callback', function () {
  var router = new Router()
  assert.throws(router.bind(router, {}, {}), /argument callback is required/)
})

The intent here is obvious, but it ended up calling the method setup here.

There are three solutions I can see:

  1. Filter out known bad names (aka blacklist)
  2. Only generate known good methods (aka whitelist)
  3. Document the fact that we overrode .bind

I can make a PR either way but wanted to open the discussion first.

Also for reference, here is the list I got by logging the methods array:

[ 'acl',
  'bind',
  'checkout',
  'connect',
  'copy',
  'delete',
  'get',
  'head',
  'link',
  'lock',
  'm-search',
  'merge',
  'mkactivity',
  'mkcalendar',
  'mkcol',
  'move',
  'notify',
  'options',
  'patch',
  'post',
  'propfind',
  'proppatch',
  'purge',
  'put',
  'rebind',
  'report',
  'search',
  'subscribe',
  'trace',
  'unbind',
  'unlink',
  'unlock',
  'unsubscribe' ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions