Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #698 from evdb/master

Specific error message for content-type of JSON but empty body.
  • Loading branch information...
commit be4a240c990bd28a64e384db8a2a65974d9b1c3e 2 parents 7f1c3ef + 5f74230
@tj tj authored
Showing with 10 additions and 1 deletion.
  1. +5 −0 lib/middleware/json.js
  2. +5 −1 test/json.js
View
5 lib/middleware/json.js
@@ -66,6 +66,11 @@ exports = module.exports = function(options){
req.on('data', function(chunk){ buf += chunk });
req.on('end', function(){
var first = buf.trim()[0];
+
+ if (0 == buf.length) {
+ return next(utils.error(400, "invalid json, empty body"));
+ }
+
if (strict && '{' != first && '[' != first) return next(utils.error(400, 'invalid json'));
try {
req.body = JSON.parse(buf, options.reviver);
View
6 test/json.js
@@ -67,7 +67,11 @@ describe('connect.json()', function(){
app.request()
.post('/')
.set('Content-Type', 'application/json')
- .expect(400, done);
+ .end(function(res) {
+ res.should.have.status(400);
+ res.body.should.include("invalid json, empty body");
+ done();
+ })
})
it('should support all http methods', function(done){
Please sign in to comment.
Something went wrong with that request. Please try again.