Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix some cases where objects were returned instead of numbers

  • Loading branch information...
commit cc61a0e580a10116c262a5226bb17ae8dfc74f96 1 parent 14d45e6
@isaacs isaacs authored
Showing with 16 additions and 16 deletions.
  1. +5 −5 lib/charset.js
  2. +5 −5 lib/encoding.js
  3. +6 −6 lib/mediaType.js
View
10 lib/charset.js
@@ -33,12 +33,12 @@ function parseCharset(s) {
}
function getCharsetPriority(charset, accepted) {
- return accepted.filter(function(a) {
+ return (accepted.filter(function(a) {
return specify(charset, a);
}).sort(function (a, b) {
// revsort
- return a.q > b.q ? -1 : 1;
- })[0] || 0;
+ return a.q === b.q ? 0 : a.q > b.q ? -1 : 1;
+ })[0] || {q:0}).q;
}
function specify(charset, spec) {
@@ -53,10 +53,10 @@ function preferredCharsets(accept, provided) {
return provided.map(function(type) {
return [type, getCharsetPriority(type, accept)];
}).filter(function(pair) {
- return pair[1].q > 0;
+ return pair[1] > 0;
}).sort(function(a, b) {
// revsort
- return a[1].q === b[1].q ? 0 : a[1].q > b[1].q ? -1 : 1;
+ return a[1] === b[1] ? 0 : a[1] > b[1] ? -1 : 1;
}).map(function(pair) {
return pair[0];
});
View
10 lib/encoding.js
@@ -51,12 +51,12 @@ function parseEncoding(s) {
}
function getEncodingPriority(encoding, accepted) {
- return accepted.filter(function(a) {
+ return (accepted.filter(function(a) {
return specify(encoding, a);
}).sort(function (a, b) {
// revsort
- return a.q > b.q ? -1 : 1;
- })[0];
+ return a.q === b.q ? 0 : a.q > b.q ? -1 : 1;
+ })[0] || {q:0}).q;
}
function specify(encoding, spec) {
@@ -71,10 +71,10 @@ function preferredEncodings(accept, provided) {
return provided.map(function(type) {
return [type, getEncodingPriority(type, accept)];
}).filter(function(pair) {
- return pair[1].q > 0;
+ return pair[1] > 0;
}).sort(function(a, b) {
// revsort
- return a[1].q === b[1].q ? 0 : a[1].q > b[1].q ? -1 : 1;
+ return a[1] === b[1] ? 0 : a[1] > b[1] ? -1 : 1;
}).map(function(pair) {
return pair[0];
});
View
12 lib/mediaType.js
@@ -23,8 +23,8 @@ function parseMediaType(s) {
params = match[3].split(';').map(function(s) {
return s.trim().split('=');
}).reduce(function (set, p) {
- params[p[0]] = p[1];
- return params
+ set[p[0]] = p[1];
+ return set
}, params);
if (params.q != null) {
@@ -43,12 +43,12 @@ function parseMediaType(s) {
}
function getMediaTypePriority(type, accepted) {
- return accepted.filter(function(a) {
+ return (accepted.filter(function(a) {
return specify(type, a);
}).sort(function (a, b) {
// revsort
return a.q > b.q ? -1 : 1;
- })[0] || 0;
+ })[0] || {q:0}).q;
}
function specifies(spec, type) {
@@ -80,10 +80,10 @@ function preferredMediaTypes(accept, provided) {
return provided.map(function(type) {
return [type, getMediaTypePriority(type, accept)];
}).filter(function(pair) {
- return pair[1].q > 0;
+ return pair[1] > 0;
}).sort(function(a, b) {
// revsort
- return a[1].q === b[1].q ? 0 : a[1].q > b[1].q ? -1 : 1;
+ return a[1] === b[1] ? 0 : a[1] > b[1] ? -1 : 1;
}).map(function(pair) {
return pair[0];
});
Please sign in to comment.
Something went wrong with that request. Please try again.