Skip to content

Commit

Permalink
fix crash when unknown extension given
Browse files Browse the repository at this point in the history
fixes #6
  • Loading branch information
dougwilson committed Jun 20, 2014
1 parent 837d900 commit fb6c4c1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
10 changes: 10 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
unreleased
==========

* fix crash when unknown extension given

1.0.4 / 2014-06-19
==================

* use `mime-types`

1.0.3 / 2014-06-11
==================

Expand Down
14 changes: 13 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Accepts.prototype.types = function (types) {
var n = this.negotiator;
if (!types.length) return n.mediaTypes();
if (!this.headers.accept) return types[0];
var mimes = types.map(extToMime);
var mimes = types.map(extToMime).filter(validMime);
var accepts = n.mediaTypes(mimes);
var first = accepts[0];
if (!first) return false;
Expand Down Expand Up @@ -146,3 +146,15 @@ function extToMime(type) {
if (~type.indexOf('/')) return type;
return mime.lookup(type);
}

/**
* Check if mime is valid.
*
* @param {String} type
* @return {String}
* @api private
*/

function validMime(type) {
return typeof type === 'string';
}
1 change: 1 addition & 0 deletions test/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ describe('accepts.types()', function(){
accept.types('txt').should.equal('txt');
accept.types('.txt').should.equal('.txt');
accept.types('png').should.be.false;
accept.types('bogus').should.be.false;
})
})

Expand Down

0 comments on commit fb6c4c1

Please sign in to comment.