Skip to content

Commit

Permalink
fix: send numbers or bools as payloads
Browse files Browse the repository at this point in the history
  • Loading branch information
DonutEspresso committed Feb 23, 2018
1 parent 644c198 commit 510718e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/response.js
Expand Up @@ -353,7 +353,9 @@ function patch(Response) {
// Check to see if the next argument is a body
if (
typeof arguments[index] === 'object' ||
typeof arguments[index] === 'string'
typeof arguments[index] === 'string' ||
typeof arguments[index] === 'boolean' ||
typeof arguments[index] === 'number'
) {
body = arguments[index++];
}
Expand Down
39 changes: 39 additions & 0 deletions test/response.test.js
Expand Up @@ -636,3 +636,42 @@ test('should support multiple set-cookie headers', function(t) {
t.end();
});
});

test('GH-1607: should send bools with explicit status code', function(t) {
SERVER.get('/bool/:value', function(req, res, next) {
res.send(200, req.params.value === 'true' ? true : false);
return next();
});

STRING_CLIENT.get(join(LOCALHOST, '/bool/false'),
function(err, req, res, data) {
t.equal(data, 'false');

STRING_CLIENT.get(join(LOCALHOST, '/bool/true'),
function(err, req, res, data) {
t.equal(data, 'true');
t.end();
});
});
});

test('GH-1607: should send numbers with explicit status code', function(t) {
SERVER.get('/zero', function(req, res, next) {
res.send(200, 0);
return next();
});

SERVER.get('/one', function(req, res, next) {
res.send(200, 1);
return next();
});

STRING_CLIENT.get(join(LOCALHOST, '/zero'), function(err, req, res, data) {
t.equal(data, '0');
STRING_CLIENT.get(join(LOCALHOST, '/one'),
function(err, req, res, data) {
t.equal(data, '1');
t.end();
});
});
});

0 comments on commit 510718e

Please sign in to comment.