Skip to content

Commit 92e9bf3

Browse files
committed
Fix regression passing request object to typeis.is
fixes #41
1 parent ef1c6ed commit 92e9bf3

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
unreleased
2+
==========
3+
4+
* Fix regression passing request object to `typeis.is`
5+
16
1.6.17 / 2019-04-25
27
===================
38

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ function normalizeType (value) {
254254
*/
255255

256256
function tryNormalizeType (value) {
257-
if (typeof value !== 'string') {
257+
if (!value) {
258258
return null
259259
}
260260

test/test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,22 @@ describe('typeis.is(mediaType, types)', function () {
292292
assert.strictEqual(typeis.is('multipart/form-data', ['multipart']), 'multipart')
293293
})
294294
})
295+
296+
describe('when give request object', function () {
297+
it('should use the content-type header', function () {
298+
var req = createRequest('image/png')
299+
300+
assert.strictEqual(typeis.is(req, ['png']), 'png')
301+
assert.strictEqual(typeis.is(req, ['jpeg']), false)
302+
})
303+
304+
it('should not check for body', function () {
305+
var req = { headers: { 'content-type': 'text/html' } }
306+
307+
assert.strictEqual(typeis.is(req, ['html']), 'html')
308+
assert.strictEqual(typeis.is(req, ['jpeg']), false)
309+
})
310+
})
295311
})
296312

297313
function createRequest (type) {

0 commit comments

Comments
 (0)