Skip to content

Commit

Permalink
Fixed fallback JSON parser to match Node
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Mar 20, 2016
1 parent a01bd83 commit 8f37194
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ Response.prototype.setHeaderProperties = function(header){

Response.prototype.parseBody = function(str){
var parse = request.parse[this.type];
if (!parse && isJSON(this.type)) {
parse = request.parse['application/json'];
}
return parse && str && (str.length || str instanceof Object)
? parse(str)
: null;
Expand Down
3 changes: 3 additions & 0 deletions test/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ describe('req.send(Object) as "json"', function(){
.end(function(err, res){
res.should.be.json
res.text.should.equal('{"tobi":"ferret"}');
({"tobi":"ferret"}).should.eql(res.body);
done();
});
});
Expand All @@ -94,6 +95,7 @@ describe('req.send(Object) as "json"', function(){
.send({ name: 'vendor' })
.end(function(err, res){
res.text.should.equal('{"name":"vendor"}');
({"name":"vendor"}).should.eql(res.body);
done();
});
});
Expand All @@ -107,6 +109,7 @@ describe('req.send(Object) as "json"', function(){
.end(function(err, res){
res.should.be.json
res.text.should.equal('{"name":"tobi","age":1}');
({"name":"tobi","age":1}).should.eql(res.body);
done();
});
})
Expand Down

0 comments on commit 8f37194

Please sign in to comment.