Skip to content

Commit

Permalink
http2: validate settings input
Browse files Browse the repository at this point in the history
The settings input was not marked as optional in our documentation
but we did not throw an error in those cases. The API does not seem
to be useful without the correct input, so I went for throwing an
error in such cases instead of updating the documentation.
  • Loading branch information
BridgeAR committed Mar 20, 2019
1 parent 4b70d2d commit 5c1b27f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,11 @@ function pingCallback(cb) {
// 6. enablePush must be a boolean
// All settings are optional and may be left undefined
function validateSettings(settings) {
if (settings === undefined) return;
if (settings === undefined) {
const err = new ERR_INVALID_ARG_TYPE('settings', 'object', settings);
Error.captureStackTrace(err, 'validateSettings');
throw err;
}
assertWithinRange('headerTableSize',
settings.headerTableSize,
0, kMaxInt);
Expand Down
6 changes: 4 additions & 2 deletions test/parallel/test-http2-getpackedsettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ http2.getPackedSettings({ enablePush: false });

// Check for not passing settings.
{
const packed = http2.getPackedSettings();
assert.strictEqual(packed.length, 0);
assert.throws(
() => http2.getPackedSettings(),
{ code: 'ERR_INVALID_ARG_TYPE' }
);
}

{
Expand Down

0 comments on commit 5c1b27f

Please sign in to comment.