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 May 17, 2018
1 parent ffed2c4 commit 26b05b5
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 @@ -28,6 +28,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 26b05b5

Please sign in to comment.