Skip to content

Commit

Permalink
Allow falsey payload. Closes #3411
Browse files Browse the repository at this point in the history
  • Loading branch information
hueniverse committed Dec 19, 2016
1 parent 7cac53c commit b0e37ab
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ internals.payload = function (request, next) {
const onParsed = (err, parsed) => {

request.mime = parsed.mime;
request.payload = parsed.payload || null;
request.payload = (parsed.payload === undefined ? null : parsed.payload);

if (!err) {
return next();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "hapi",
"description": "HTTP Server framework",
"homepage": "http://hapijs.com",
"version": "16.0.1",
"version": "16.0.2",
"repository": {
"type": "git",
"url": "git://github.com/hapijs/hapi"
Expand Down
25 changes: 25 additions & 0 deletions test/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,31 @@ describe('validation', () => {
});
});

it('validates boolean payload', (done) => {

const server = new Hapi.Server();
server.connection();
server.route({
method: 'POST',
path: '/',
handler: function (request, reply) {

return reply('ok');
},
config: {
validate: {
payload: Joi.boolean()
}
}
});

server.inject({ method: 'POST', url: '/', payload: 'false', headers: { 'content-type': 'application/json' } }, (res) => {

expect(res.statusCode).to.equal(200);
done();
});
});

it('fails on invalid input', (done) => {

const server = new Hapi.Server();
Expand Down

0 comments on commit b0e37ab

Please sign in to comment.