Skip to content

Commit

Permalink
fix(binary): add type checking for buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
kvwalker authored and daprahamian committed May 31, 2018
1 parent 00a7f57 commit cbfb25d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/bson/binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ if (typeof global !== 'undefined') {
function Binary(buffer, subType) {
if (!(this instanceof Binary)) return new Binary(buffer, subType);

if (
buffer != null &&
!(typeof buffer === 'string') &&
!Buffer.isBuffer(buffer) &&
!(buffer instanceof Uint8Array) &&
!Array.isArray(buffer)
) {
throw new Error('only String, Buffer, Uint8Array or Array accepted');
}

this._bsontype = 'Binary';

if (buffer instanceof Number) {
Expand Down

0 comments on commit cbfb25d

Please sign in to comment.