From 52a6c30487a2b6a1647d1b2f19f095e9389fe2af Mon Sep 17 00:00:00 2001 From: John Deerhake Date: Fri, 24 Jan 2014 13:04:16 -0800 Subject: [PATCH 1/2] mediaTypePriority not sorting correctly because it's using the wrong object to sort --- lib/mediaType.js | 4 +++- test/mediaType.js | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/mediaType.js b/lib/mediaType.js index 0c423aa..c21de73 100644 --- a/lib/mediaType.js +++ b/lib/mediaType.js @@ -43,8 +43,10 @@ function parseMediaType(s) { } function getMediaTypePriority(type, accepted) { - return (accepted.filter(function(a) { + return (accepted.map(function(a) { return specify(type, a); + }).filter(function(a) { + return a; }).sort(function (a, b) { // revsort return a.s > b.s ? -1 : 1; diff --git a/test/mediaType.js b/test/mediaType.js index 6a811a7..f20c58e 100644 --- a/test/mediaType.js +++ b/test/mediaType.js @@ -67,6 +67,10 @@ accept: 'text/*, text/html;q=0.5', provided: ['text/html', 'text/plain'], selected: ['text/plain', 'text/html'] + }, { + accept: 'application/json, */*; q=0.01', + provided: ['text/html', 'application/json'], + selected: ['application/json', 'text/html'] } ]; From c1ed40663af1984225a3298cdf32052e7a06d700 Mon Sep 17 00:00:00 2001 From: John Deerhake Date: Fri, 24 Jan 2014 14:11:45 -0800 Subject: [PATCH 2/2] Remove identity function and use Boolean as a shortcut --- lib/mediaType.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/mediaType.js b/lib/mediaType.js index c21de73..fe6d37a 100644 --- a/lib/mediaType.js +++ b/lib/mediaType.js @@ -45,9 +45,7 @@ function parseMediaType(s) { function getMediaTypePriority(type, accepted) { return (accepted.map(function(a) { return specify(type, a); - }).filter(function(a) { - return a; - }).sort(function (a, b) { + }).filter(Boolean).sort(function (a, b) { // revsort return a.s > b.s ? -1 : 1; })[0] || {q:0}).q;