Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upapplyFilter: handle empty payloads #338
Conversation
@@ -87,6 +87,8 @@ exports.GreatResponse = function (request, options, filterRules) { | |||
|
|||
var applyFilter = function (data) { | |||
|
|||
if(!data || Object.keys(data).length === 0) return; |
This comment has been minimized.
This comment has been minimized.
arb
Apr 26, 2015
Contributor
I think the check should be for !(data && typeof data === 'object')
. While null
or undefined
cause an issue, plain string responses or payloads cause the problem too.
Also, please check the style guide. If statements must have brackets around the body.
This comment has been minimized.
This comment has been minimized.
dvic
Apr 26, 2015
Author
Contributor
I added also the condition Object.keys(data).length > 0
, as empty objects also seem to cause this bug.
|
||
it('handles empty request payloads', function (done) { | ||
|
||
generateGreatResponse(null, {message: 'test'}); |
This comment has been minimized.
This comment has been minimized.
it('handles empty request payloads', function (done) { | ||
|
||
generateGreatResponse(null, {message: 'test'}); | ||
generateGreatResponse({}, {message: 'test'}); |
This comment has been minimized.
This comment has been minimized.
describe('GreatResponse()', function () { | ||
|
||
var generateGreatResponse = function (requestPayload, responsePayload) { | ||
var filterRules = { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
After some experimenting, I found a better fix for this: change the first few lines of the if (this.isRoot) {
return;
} Then you won't need any of the other checks. I'd like to avoid anything |
This comment has been minimized.
This comment has been minimized.
Good find, thanks for the PR! |
applyFilter: handle empty payloads
dvic commentedApr 25, 2015
Fixes #337. This handles the case when a payload is null (e.g., not posted with a
POST
method or masked by Hapi in case ofGET
method).By the way: is it correct that Hapi passes null for the payload when a
GET
method is performed?