Skip to content

Commit 8a18f9f

Browse files
committed
Fix comparing media types with quoted values
fixes #36
1 parent 4f40e4f commit 8a18f9f

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
unreleased
22
==========
33

4+
* Fix comparing media types with quoted values
45
* Fix splitting media types with quoted commas
56

67
0.5.1 / 2015-02-14

lib/mediaType.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,14 @@ function parseMediaType(s, i) {
3232
params = match[3].split(';').map(function(s) {
3333
return s.trim().split('=');
3434
}).reduce(function (set, p) {
35-
set[p[0]] = p[1];
36-
return set
35+
var name = p[0];
36+
var value = p[1];
37+
38+
set[name] = value && value[0] === '"' && value[value.length - 1] === '"'
39+
? value.substr(1, value.length - 2)
40+
: value;
41+
42+
return set;
3743
}, params);
3844

3945
if (params.q != null) {

test/mediaType.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,18 @@ describe('negotiator.mediaTypes(array)', function () {
334334
))
335335
})
336336

337+
whenAccept('text/html;level=1;foo="bar"', function () {
338+
it('should accept text/html;level=1;foo=bar', mediaTypesNegotiated(
339+
['text/html;level=1;foo=bar'],
340+
['text/html;level=1;foo=bar']
341+
))
342+
343+
it('should accept text/html;level=1;foo="bar"', mediaTypesNegotiated(
344+
['text/html;level=1;foo="bar"'],
345+
['text/html;level=1;foo="bar"']
346+
))
347+
})
348+
337349
whenAccept('text/html;level=2', function () {
338350
it('should not accept text/html;level=1', mediaTypesNegotiated(
339351
['text/html;level=1'],

0 commit comments

Comments
 (0)